Helper class for defining types
Наследование: IType
Пример #1
0
 public MethodBuilder(TypeBuilder typeBuilder, string name,
                      MethodAttributes attributes, IEnumerable<Type> parameters, Type returnType)
 {
     if (typeBuilder == null)
         throw new ArgumentNullException("typeBuilder");
     if (string.IsNullOrEmpty(name))
         throw new ArgumentNullException("name");
     Name = name;
     Type = typeBuilder;
     Attributes = attributes;
     ReturnType = (returnType == null) ? typeof (void) : returnType;
     Parameters = new List<ParameterBuilder>();
     Parameters.Add(new ParameterBuilder(null, 0));
     if (parameters != null)
     {
         int x = 1;
         if (name.StartsWith("set_", StringComparison.InvariantCulture))
             x = -1;
         foreach (var parameterType in parameters)
         {
             Parameters.Add(new ParameterBuilder(parameterType, x));
             ++x;
         }
     }
     Builder = Type.Builder.DefineMethod(name, attributes, returnType,
                                         (parameters != null && parameters.Count() > 0)
                                             ? parameters.ToArray()
                                             : System.Type.EmptyTypes);
     Generator = Builder.GetILGenerator();
 }
Пример #2
0
 /// <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,
                           IEnumerable<Type> parameters, CallingConventions callingConventions)
 {
     if (typeBuilder == null)
         throw new ArgumentNullException("typeBuilder");
     Type = typeBuilder;
     Attributes = attributes;
     Parameters = new List<ParameterBuilder>();
     Parameters.Add(new ParameterBuilder(null, 0));
     if (parameters != null)
     {
         int x = 1;
         foreach (var parameterType in parameters)
         {
             Parameters.Add(new ParameterBuilder(parameterType, x));
             ++x;
         }
     }
     CallingConventions = callingConventions;
     Builder = Type.Builder.DefineConstructor(attributes, callingConventions,
                                              (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>
 public DefaultConstructorBuilder(TypeBuilder typeBuilder, MethodAttributes attributes)
 {
     if (typeBuilder == null)
         throw new ArgumentNullException("typeBuilder");
     Type = typeBuilder;
     Attributes = attributes;
     Builder = Type.Builder.DefineDefaultConstructor(attributes);
     Generator = null;
     Parameters = new List<ParameterBuilder>();
     Parameters.Add(new ParameterBuilder(null, 0));
 }