/// <summary> /// Constructor /// </summary> /// <param name="TypeBuilder">Type builder</param> /// <param name="Name">Name of the method</param> /// <param name="Attributes">Attributes for the method (public, private, etc.)</param> /// <param name="Parameters">Parameter types for the method</param> /// <param name="ReturnType">Return type for the method</param> public MethodBuilder(TypeBuilder TypeBuilder, string Name, MethodAttributes Attributes, List<Type> Parameters, Type ReturnType) : base() { if (TypeBuilder == null) throw new ArgumentNullException("TypeBuilder"); if (string.IsNullOrEmpty(Name)) throw new ArgumentNullException("Name"); this.Name = Name; this.Type = TypeBuilder; this.Attributes = Attributes; this.ReturnType = (ReturnType == null) ? typeof(void) : ReturnType; this.Parameters = new List<ParameterBuilder>(); this.Parameters.Add(new ParameterBuilder(null, 0)); if (Parameters != null) { int x = 1; if (Name.StartsWith("set_")) x = -1; foreach (Type ParameterType in Parameters) { this.Parameters.Add(new ParameterBuilder(ParameterType, x)); ++x; } } Commands = new List<ICommand>(); Builder = Type.Builder.DefineMethod(Name, Attributes, ReturnType, (Parameters != null && Parameters.Count > 0) ? Parameters.ToArray() : System.Type.EmptyTypes); Generator = Builder.GetILGenerator(); }
/// <summary> /// Constructor /// </summary> /// <param name="TypeBuilder">Type builder</param> /// <param name="Attributes">Attributes for the constructor (public, private, etc.)</param> /// <param name="Parameters">Parameter types for the constructor</param> /// <param name="CallingConventions">Calling convention for the constructor</param> public ConstructorBuilder(TypeBuilder TypeBuilder, MethodAttributes Attributes, List<Type> Parameters, CallingConventions CallingConventions) : base() { if (TypeBuilder == null) throw new ArgumentNullException("TypeBuilder"); this.Type = TypeBuilder; this.Attributes = Attributes; this.Parameters = new List<ParameterBuilder>(); this.Parameters.Add(new ParameterBuilder(null, 0)); if (Parameters != null) { int x = 1; foreach (Type ParameterType in Parameters) { this.Parameters.Add(new ParameterBuilder(ParameterType, x)); ++x; } } this.CallingConventions = CallingConventions; this.Builder = Type.Builder.DefineConstructor(Attributes, CallingConventions, (Parameters != null && Parameters.Count > 0) ? Parameters.ToArray() : System.Type.EmptyTypes); this.Generator = Builder.GetILGenerator(); }