System.Reflection.Emit.TypeBuilder.DefineMethod C# (CSharp) Method

DefineMethod() public method

public DefineMethod ( string name, System attributes ) : System.Reflection.Emit.MethodBuilder
name string
attributes System
return System.Reflection.Emit.MethodBuilder
        public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes) { throw null; }
        public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention) { throw null; }

Same methods

TypeBuilder::DefineMethod ( string name, System attributes, System callingConvention ) : System.Reflection.Emit.MethodBuilder
TypeBuilder::DefineMethod ( string name, System attributes, System returnType, System parameterTypes ) : System.Reflection.Emit.MethodBuilder
TypeBuilder::DefineMethod ( string name, System attributes, System callingConvention, System returnType, System parameterTypes ) : System.Reflection.Emit.MethodBuilder
TypeBuilder::DefineMethod ( string name, System attributes, System callingConvention, System returnType, System returnTypeRequiredCustomModifiers, System returnTypeOptionalCustomModifiers, System parameterTypes, System parameterTypeRequiredCustomModifiers, System parameterTypeOptionalCustomModifiers ) : System.Reflection.Emit.MethodBuilder

Usage Example

		public void CreateProxiedMethod(FieldInfo field, MethodInfo method, TypeBuilder typeBuilder)
		{
			const MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig |
																								MethodAttributes.Virtual;
			ParameterInfo[] parameters = method.GetParameters();

			MethodBuilder methodBuilder = typeBuilder.DefineMethod(method.Name, methodAttributes,
			                                                       CallingConventions.HasThis, method.ReturnType,
			                                                       parameters.Select(param => param.ParameterType).ToArray());

			System.Type[] typeArgs = method.GetGenericArguments();

			if (typeArgs.Length > 0)
			{
				var typeNames = new List<string>();

				for (int index = 0; index < typeArgs.Length; index++)
				{
					typeNames.Add(string.Format("T{0}", index));
				}

				methodBuilder.DefineGenericParameters(typeNames.ToArray());
			}

			ILGenerator IL = methodBuilder.GetILGenerator();

			Debug.Assert(MethodBodyEmitter != null);
			MethodBodyEmitter.EmitMethodBody(IL, method, field);
		}
All Usage Examples Of System.Reflection.Emit.TypeBuilder::DefineMethod