Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / clr / src / BCL / System / Reflection / Emit / ConstructorBuilder.cs / 1 / ConstructorBuilder.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== namespace System.Reflection.Emit { using System; using System.Reflection; using CultureInfo = System.Globalization.CultureInfo; using System.Diagnostics.SymbolStore; using System.Security; using System.Security.Permissions; using System.Runtime.InteropServices; [HostProtection(MayLeakOnAbort = true)] [ClassInterface(ClassInterfaceType.None)] [ComDefaultInterface(typeof(_ConstructorBuilder))] [System.Runtime.InteropServices.ComVisible(true)] public sealed class ConstructorBuilder : ConstructorInfo, _ConstructorBuilder { #region Private Data Members internal MethodBuilder m_methodBuilder; internal bool m_ReturnILGen; #endregion #region Constructor private ConstructorBuilder() { } internal ConstructorBuilder(String name, MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers, Module mod, TypeBuilder type) { int sigLength; byte[] sigBytes; MethodToken token; m_methodBuilder = new MethodBuilder(name, attributes, callingConvention, null, null, null, parameterTypes, requiredCustomModifiers, optionalCustomModifiers, mod, type, false); type.m_listMethods.Add(m_methodBuilder); sigBytes = m_methodBuilder.GetMethodSignature().InternalGetSignature(out sigLength); token = m_methodBuilder.GetToken(); m_ReturnILGen = true; } internal ConstructorBuilder(String name, MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Module mod, TypeBuilder type) : this(name, attributes, callingConvention, parameterTypes, null, null, mod, type) { } #endregion #region Internal internal override Type[] GetParameterTypes() { return m_methodBuilder.GetParameterTypes(); } #endregion #region Object Overrides public override String ToString() { return m_methodBuilder.ToString(); } #endregion #region MemberInfo Overrides internal override int MetadataTokenInternal { get { return m_methodBuilder.MetadataTokenInternal; } } public override Module Module { get { return m_methodBuilder.Module; } } public override Type ReflectedType { get { return m_methodBuilder.ReflectedType; } } public override Type DeclaringType { get { return m_methodBuilder.DeclaringType; } } public override String Name { get { return m_methodBuilder.Name; } } #endregion #region MethodBase Overrides public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule")); } public override ParameterInfo[] GetParameters() { if (!m_methodBuilder.m_bIsBaked) throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_TypeNotCreated")); Type rti = m_methodBuilder.GetTypeBuilder().m_runtimeType; ConstructorInfo rci = rti.GetConstructor(m_methodBuilder.m_parameterTypes); return rci.GetParameters(); } public override MethodAttributes Attributes { get { return m_methodBuilder.Attributes; } } public override MethodImplAttributes GetMethodImplementationFlags() { return m_methodBuilder.GetMethodImplementationFlags(); } public override RuntimeMethodHandle MethodHandle { get { return m_methodBuilder.MethodHandle; } } #endregion #region ConstructorInfo Overrides public override Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule")); } #endregion #region ICustomAttributeProvider Implementation public override Object[] GetCustomAttributes(bool inherit) { return m_methodBuilder.GetCustomAttributes(inherit); } public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { return m_methodBuilder.GetCustomAttributes(attributeType, inherit); } public override bool IsDefined (Type attributeType, bool inherit) { return m_methodBuilder.IsDefined(attributeType, inherit); } #endregion #region Public Members public MethodToken GetToken() { return m_methodBuilder.GetToken(); } public ParameterBuilder DefineParameter(int iSequence, ParameterAttributes attributes, String strParamName) { // MD will assert if we try to set the reserved bits explicitly attributes = attributes & ~ParameterAttributes.ReservedMask; return m_methodBuilder.DefineParameter(iSequence, attributes, strParamName); } public void SetSymCustomAttribute(String name, byte[] data) { m_methodBuilder.SetSymCustomAttribute(name, data); } public ILGenerator GetILGenerator() { if (!m_ReturnILGen) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_DefaultConstructorILGen")); return m_methodBuilder.GetILGenerator(); } public ILGenerator GetILGenerator(int streamSize) { if (!m_ReturnILGen) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_DefaultConstructorILGen")); return m_methodBuilder.GetILGenerator(streamSize); } public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { if (pset == null) throw new ArgumentNullException("pset"); if (!Enum.IsDefined(typeof(SecurityAction), action) || action == SecurityAction.RequestMinimum || action == SecurityAction.RequestOptional || action == SecurityAction.RequestRefuse ) throw new ArgumentOutOfRangeException("action"); // Cannot add declarative security after type is created. if (m_methodBuilder.IsTypeCreated()) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated")); // Translate permission set into serialized format (use standard binary serialization). byte[] blob = pset.EncodeXml(); // Write the blob into the metadata. TypeBuilder.InternalAddDeclarativeSecurity(GetModule(), GetToken().Token, action, blob); } public override CallingConventions CallingConvention { get { if (DeclaringType.IsGenericType) return CallingConventions.HasThis; return CallingConventions.Standard; } } public Module GetModule() { return m_methodBuilder.GetModule(); } public Type ReturnType { get { return m_methodBuilder.GetReturnType(); } } internal override Type GetReturnType() { return m_methodBuilder.GetReturnType(); } public String Signature { get { return m_methodBuilder.Signature; } } [System.Runtime.InteropServices.ComVisible(true)] public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) { m_methodBuilder.SetCustomAttribute(con, binaryAttribute); } public void SetCustomAttribute(CustomAttributeBuilder customBuilder) { m_methodBuilder.SetCustomAttribute(customBuilder); } public void SetImplementationFlags(MethodImplAttributes attributes) { m_methodBuilder.SetImplementationFlags(attributes); } public bool InitLocals { get { return m_methodBuilder.InitLocals; } set { m_methodBuilder.InitLocals = value; } } #endregion void _ConstructorBuilder.GetTypeInfoCount(out uint pcTInfo) { throw new NotImplementedException(); } void _ConstructorBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo) { throw new NotImplementedException(); } void _ConstructorBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId) { throw new NotImplementedException(); } void _ConstructorBuilder.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr) { throw new NotImplementedException(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== namespace System.Reflection.Emit { using System; using System.Reflection; using CultureInfo = System.Globalization.CultureInfo; using System.Diagnostics.SymbolStore; using System.Security; using System.Security.Permissions; using System.Runtime.InteropServices; [HostProtection(MayLeakOnAbort = true)] [ClassInterface(ClassInterfaceType.None)] [ComDefaultInterface(typeof(_ConstructorBuilder))] [System.Runtime.InteropServices.ComVisible(true)] public sealed class ConstructorBuilder : ConstructorInfo, _ConstructorBuilder { #region Private Data Members internal MethodBuilder m_methodBuilder; internal bool m_ReturnILGen; #endregion #region Constructor private ConstructorBuilder() { } internal ConstructorBuilder(String name, MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers, Module mod, TypeBuilder type) { int sigLength; byte[] sigBytes; MethodToken token; m_methodBuilder = new MethodBuilder(name, attributes, callingConvention, null, null, null, parameterTypes, requiredCustomModifiers, optionalCustomModifiers, mod, type, false); type.m_listMethods.Add(m_methodBuilder); sigBytes = m_methodBuilder.GetMethodSignature().InternalGetSignature(out sigLength); token = m_methodBuilder.GetToken(); m_ReturnILGen = true; } internal ConstructorBuilder(String name, MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Module mod, TypeBuilder type) : this(name, attributes, callingConvention, parameterTypes, null, null, mod, type) { } #endregion #region Internal internal override Type[] GetParameterTypes() { return m_methodBuilder.GetParameterTypes(); } #endregion #region Object Overrides public override String ToString() { return m_methodBuilder.ToString(); } #endregion #region MemberInfo Overrides internal override int MetadataTokenInternal { get { return m_methodBuilder.MetadataTokenInternal; } } public override Module Module { get { return m_methodBuilder.Module; } } public override Type ReflectedType { get { return m_methodBuilder.ReflectedType; } } public override Type DeclaringType { get { return m_methodBuilder.DeclaringType; } } public override String Name { get { return m_methodBuilder.Name; } } #endregion #region MethodBase Overrides public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule")); } public override ParameterInfo[] GetParameters() { if (!m_methodBuilder.m_bIsBaked) throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_TypeNotCreated")); Type rti = m_methodBuilder.GetTypeBuilder().m_runtimeType; ConstructorInfo rci = rti.GetConstructor(m_methodBuilder.m_parameterTypes); return rci.GetParameters(); } public override MethodAttributes Attributes { get { return m_methodBuilder.Attributes; } } public override MethodImplAttributes GetMethodImplementationFlags() { return m_methodBuilder.GetMethodImplementationFlags(); } public override RuntimeMethodHandle MethodHandle { get { return m_methodBuilder.MethodHandle; } } #endregion #region ConstructorInfo Overrides public override Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule")); } #endregion #region ICustomAttributeProvider Implementation public override Object[] GetCustomAttributes(bool inherit) { return m_methodBuilder.GetCustomAttributes(inherit); } public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { return m_methodBuilder.GetCustomAttributes(attributeType, inherit); } public override bool IsDefined (Type attributeType, bool inherit) { return m_methodBuilder.IsDefined(attributeType, inherit); } #endregion #region Public Members public MethodToken GetToken() { return m_methodBuilder.GetToken(); } public ParameterBuilder DefineParameter(int iSequence, ParameterAttributes attributes, String strParamName) { // MD will assert if we try to set the reserved bits explicitly attributes = attributes & ~ParameterAttributes.ReservedMask; return m_methodBuilder.DefineParameter(iSequence, attributes, strParamName); } public void SetSymCustomAttribute(String name, byte[] data) { m_methodBuilder.SetSymCustomAttribute(name, data); } public ILGenerator GetILGenerator() { if (!m_ReturnILGen) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_DefaultConstructorILGen")); return m_methodBuilder.GetILGenerator(); } public ILGenerator GetILGenerator(int streamSize) { if (!m_ReturnILGen) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_DefaultConstructorILGen")); return m_methodBuilder.GetILGenerator(streamSize); } public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { if (pset == null) throw new ArgumentNullException("pset"); if (!Enum.IsDefined(typeof(SecurityAction), action) || action == SecurityAction.RequestMinimum || action == SecurityAction.RequestOptional || action == SecurityAction.RequestRefuse ) throw new ArgumentOutOfRangeException("action"); // Cannot add declarative security after type is created. if (m_methodBuilder.IsTypeCreated()) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated")); // Translate permission set into serialized format (use standard binary serialization). byte[] blob = pset.EncodeXml(); // Write the blob into the metadata. TypeBuilder.InternalAddDeclarativeSecurity(GetModule(), GetToken().Token, action, blob); } public override CallingConventions CallingConvention { get { if (DeclaringType.IsGenericType) return CallingConventions.HasThis; return CallingConventions.Standard; } } public Module GetModule() { return m_methodBuilder.GetModule(); } public Type ReturnType { get { return m_methodBuilder.GetReturnType(); } } internal override Type GetReturnType() { return m_methodBuilder.GetReturnType(); } public String Signature { get { return m_methodBuilder.Signature; } } [System.Runtime.InteropServices.ComVisible(true)] public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) { m_methodBuilder.SetCustomAttribute(con, binaryAttribute); } public void SetCustomAttribute(CustomAttributeBuilder customBuilder) { m_methodBuilder.SetCustomAttribute(customBuilder); } public void SetImplementationFlags(MethodImplAttributes attributes) { m_methodBuilder.SetImplementationFlags(attributes); } public bool InitLocals { get { return m_methodBuilder.InitLocals; } set { m_methodBuilder.InitLocals = value; } } #endregion void _ConstructorBuilder.GetTypeInfoCount(out uint pcTInfo) { throw new NotImplementedException(); } void _ConstructorBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo) { throw new NotImplementedException(); } void _ConstructorBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId) { throw new NotImplementedException(); } void _ConstructorBuilder.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr) { throw new NotImplementedException(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DependencyPropertyAttribute.cs
- TypeUsage.cs
- XPathPatternBuilder.cs
- ContentPropertyAttribute.cs
- PipelineModuleStepContainer.cs
- TransformPattern.cs
- OracleEncoding.cs
- TextBox.cs
- dataobject.cs
- SqlProviderManifest.cs
- BufferModesCollection.cs
- ObjectMemberMapping.cs
- ContentValidator.cs
- SmtpLoginAuthenticationModule.cs
- XmlnsCache.cs
- Model3DGroup.cs
- ScriptModule.cs
- ASCIIEncoding.cs
- DefaultBinder.cs
- Transform3DCollection.cs
- CategoriesDocumentFormatter.cs
- TextEditorDragDrop.cs
- DBCommandBuilder.cs
- GenericEnumerator.cs
- ResourceAssociationTypeEnd.cs
- WebPartsPersonalization.cs
- TargetParameterCountException.cs
- CodeGeneratorOptions.cs
- TraceLevelStore.cs
- GridViewAutomationPeer.cs
- XmlSchemaAnnotation.cs
- TreeNode.cs
- ServiceDurableInstanceContextProvider.cs
- Registry.cs
- _ProxyChain.cs
- ExpressionLexer.cs
- SingleAnimation.cs
- ProfileSection.cs
- OracleBinary.cs
- NumericUpDownAccelerationCollection.cs
- ISCIIEncoding.cs
- ConfigurationProperty.cs
- Separator.cs
- SafeNativeMethodsMilCoreApi.cs
- EventHandlersStore.cs
- SmiEventSink_Default.cs
- FamilyTypefaceCollection.cs
- CertificateManager.cs
- TextFormatterContext.cs
- XPathPatternParser.cs
- FrameworkObject.cs
- ExtensionDataObject.cs
- FormatConvertedBitmap.cs
- SchemaLookupTable.cs
- IISMapPath.cs
- Content.cs
- XhtmlBasicCommandAdapter.cs
- DriveInfo.cs
- Vector3DCollection.cs
- AnchorEditor.cs
- PersonalizationEntry.cs
- BinHexDecoder.cs
- SimplePropertyEntry.cs
- SoapCodeExporter.cs
- TokenBasedSetEnumerator.cs
- assertwrapper.cs
- COM2AboutBoxPropertyDescriptor.cs
- WorkflowInstanceProvider.cs
- TimersDescriptionAttribute.cs
- DbCommandTree.cs
- SafeNativeHandle.cs
- TypedDataSourceCodeGenerator.cs
- DbProviderSpecificTypePropertyAttribute.cs
- TextBox.cs
- HttpRuntimeSection.cs
- XomlCompilerError.cs
- IPEndPointCollection.cs
- FormsIdentity.cs
- Overlapped.cs
- Vars.cs
- MouseOverProperty.cs
- DuplexSecurityProtocolFactory.cs
- InfoCardTrace.cs
- Pair.cs
- CalendarDateRange.cs
- Literal.cs
- SmtpSection.cs
- ImageInfo.cs
- path.cs
- SingleResultAttribute.cs
- BmpBitmapEncoder.cs
- IgnoreDeviceFilterElement.cs
- MatrixUtil.cs
- Cursor.cs
- TextBoxAutoCompleteSourceConverter.cs
- MailMessageEventArgs.cs
- XMLDiffLoader.cs
- ParsedAttributeCollection.cs
- WebPartEditorCancelVerb.cs
- EditorPartChrome.cs