This class represents a dynamically created method. Methods are created with TypeBuilder.DefineMethod( ) . When creating a method, specify the name , parameters, and return type. You can also specify other characteristics of the method, such as whether it is static, abstract, or virtual, by using the System.Reflection.MethodAttributes enumeration. After creating a method, you can specify how the return value will be marshaled to unmanaged code using SetMarshal( ) , and add declarative security using AddDeclarativeSecurity( ) . You must specify the security action (such as Demand, Assert, Deny) using the System.Security.Permissions.SecurityAction enumeration and the permissions required using the System.Security.PermissionSet collection class. You can call AddDeclarativeSecurity( ) several times to specify different security actions. To create a global method builder, use ModuleBuilder.DefineGlobalMethod( ) . You must also use ModuleBuilder.CreateGlobalFunctions( ) to finish creating global methods before you persist or use the dynamic module. Global methods must be static. You can also create a global native method using ModuleBuilder.DefinePInvokeMethod( ) . PInvoke methods cannot be abstract or virtual. public sealed class MethodBuilder : System.Reflection.MethodInfo { // Public Instance Properties public override MethodAttributes Attributes {get; } // overrides System.Reflection.MethodBase public override CallingConventions CallingConvention {get; } // overrides System.Reflection.MethodBase public override Type DeclaringType {get; } // overrides System.Reflection.MemberInfo public bool InitLocals {set; get; } public override RuntimeMethodHandle MethodHandle {get; } // overrides System.Reflection.MethodBase public override string Name {get; } // overrides System.Reflection.MemberInfo public override Type ReflectedType {get; } // overrides System.Reflection.MemberInfo public override Type ReturnType {get; } // overrides System.Reflection.MethodInfo public override ICustomAttributeProvider ReturnTypeCustomAttributes {get; } // overrides System.Reflection.MethodInfo public string Signature {get; } // Public Instance Methods public void AddDeclarativeSecurity (System.Security.Permissions.SecurityAction action , System.Security.PermissionSet pset ); public void CreateMethodBody (byte[ ] il , int count ); public ParameterBuilder DefineParameter (int position , System.Reflection.ParameterAttributes attributes , string strParamName ); public override bool Equals (object obj ); // overrides object public override MethodInfo GetBaseDefinition ( ); // overrides System.Reflection.MethodInfo public override object[ ] GetCustomAttributes (bool inherit ) // overrides System.Reflection.MemberInfo public override object[ ] GetCustomAttributes (Type attributeType ,bool inherit ) // overrides System.Reflection.MemberInfo public override int GetHashCode ( ); // overrides object public ILGenerator GetILGenerator ( ); public ILGenerator GetILGenerator (int size ); public override MethodImplAttributes GetMethodImplementationFlags ( ) // overrides System.Reflection.MethodBase public Module GetModule ( ); public override ParameterInfo[ ] GetParameters ( ); // overrides System.Reflection.MethodBase public MethodToken GetToken ( ); public override object Invoke (object obj , System.Reflection.BindingFlags invokeAttr , System.Reflection.Binder binder , object[ ] parameters , System.Globalization.CultureInfo culture ) // overrides System.Reflection.MethodBase public override bool IsDefined (Type attributeType , bool inherit ); // overrides System.Reflection.MemberInfo public void SetCustomAttribute (System.Reflection.ConstructorInfo con , byte[ ] binaryAttribute ); public void SetCustomAttribute (CustomAttributeBuilder customBuilder ); public void SetImplementationFlags (System.Reflection.MethodImplAttributes attributes ); public void SetMarshal (UnmanagedMarshal unmanagedMarshal ); public void SetSymCustomAttribute (string name , byte[ ] data ); public override string ToString ( ); // overrides object } HierarchySystem.Object System.Reflection.MemberInfo(System.Reflection.ICustomAttributeProvider) System.Reflection.MethodBase System.Reflection.MethodInfo MethodBuilder Returned ByModuleBuilder.{DefineGlobalMethod( ) , DefinePInvokeMethod( )} , TypeBuilder.{DefineMethod( ) , DefinePInvokeMethod( )} Passed ToEventBuilder.{AddOtherMethod( ) , SetAddOnMethod( ) , SetRaiseMethod( ) , SetRemoveOnMethod( )} , PropertyBuilder.{AddOtherMethod( ) , SetGetMethod( ) , SetSetMethod( )} |