// private ParameterInfo[] indexParameters;

        public PropertyEmitter(AbstractTypeEmitter parentTypeEmitter, string name, PropertyAttributes attributes,
                               Type propertyType, Type[] arguments)
        {
            this.parentTypeEmitter = parentTypeEmitter;

            // DYNPROXY-73 - AmbiguousMatchException for properties
            // This is a workaround for a framework limitation in CLR 2.0
            // This limitation was removed in CLR 2.0 SP1, but we don't want to
            // tie ourselves to that version. This perform the lookup for the new overload
            // dynamically, so we have a nice fallback on vanilla CLR 2.0

            if (TypeBuilderMethods.DefineProperty == null)
            {
                DefineProperty_Clr2_0 oldDefineProperty = parentTypeEmitter.TypeBuilder.DefineProperty;
                builder = oldDefineProperty(name, attributes, propertyType, arguments);
            }
            else
            {
                var newDefinedProperty = (DefineProperty_Clr_2_0_SP1)
                                         Delegate.CreateDelegate(typeof(DefineProperty_Clr_2_0_SP1),
                                                                 parentTypeEmitter.TypeBuilder,
                                                                 TypeBuilderMethods.DefineProperty);
                builder = newDefinedProperty(
                    name, attributes, CallingConventions.HasThis, propertyType,
                    null, null, arguments, null, null);
            }
        }
Beispiel #2
0
 public NestedClassEmitter(AbstractTypeEmitter maintype, String name, Type baseType, Type[] interfaces)
     : this(
         maintype,
         CreateTypeBuilder(maintype, name, TypeAttributes.Sealed | TypeAttributes.NestedPublic | TypeAttributes.Class,
                           baseType, interfaces))
 {
 }
        internal ConstructorEmitter(AbstractTypeEmitter maintype, params ArgumentReference[] arguments)
        {
            this.maintype = maintype;

            var args = ArgumentsUtil.InitializeAndConvert(arguments);

            builder = maintype.TypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, args);
        }
Beispiel #4
0
 internal MethodEmitter(AbstractTypeEmitter owner, String name,
                        MethodAttributes attributes, Type returnType,
                        params Type[] argumentTypes)
     : this(owner, name, attributes)
 {
     SetParameters(argumentTypes);
     SetReturnType(returnType);
 }
Beispiel #5
0
 private static TypeBuilder CreateTypeBuilder(AbstractTypeEmitter maintype, string name, TypeAttributes attributes,
                                              Type baseType, Type[] interfaces)
 {
     return(maintype.TypeBuilder.DefineNestedType(
                name,
                attributes,
                baseType, interfaces));
 }
Beispiel #6
0
 public EventEmitter(AbstractTypeEmitter typeEmitter, string name, EventAttributes attributes, Type type)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     this.typeEmitter = typeEmitter;
     this.type        = type;
     eventBuilder     = typeEmitter.TypeBuilder.DefineEvent(name, attributes, type);
 }
Beispiel #7
0
        internal MethodEmitter(AbstractTypeEmitter owner, String name,
                               MethodAttributes attributes, MethodInfo methodToUseAsATemplate)
            : this(owner, name, attributes)
        {
            var name2GenericType = GenericUtil.GetGenericArgumentsMap(owner);

            var returnType           = GenericUtil.ExtractCorrectType(methodToUseAsATemplate.ReturnType, name2GenericType);
            var baseMethodParameters = methodToUseAsATemplate.GetParameters();
            var parameters           = GenericUtil.ExtractParametersTypes(baseMethodParameters, name2GenericType);

            genericTypeParams = GenericUtil.CopyGenericArguments(methodToUseAsATemplate, builder, name2GenericType);
            SetParameters(parameters);
            SetReturnType(returnType);
            SetSignature(returnType, methodToUseAsATemplate.ReturnParameter, parameters, baseMethodParameters);
            DefineParameters(baseMethodParameters);
        }
 protected internal ConstructorEmitter(AbstractTypeEmitter maintype, ConstructorBuilder builder)
 {
     this.maintype = maintype;
     this.builder  = builder;
 }
Beispiel #9
0
 internal MethodEmitter(AbstractTypeEmitter owner, String name, MethodAttributes attributes)
     : this(owner.TypeBuilder.DefineMethod(name, attributes))
 {
 }
Beispiel #10
0
        public static Dictionary <string, GenericTypeParameterBuilder> GetGenericArgumentsMap(AbstractTypeEmitter parentEmitter)
        {
            if (parentEmitter.GenericTypeParams == null || parentEmitter.GenericTypeParams.Length == 0)
            {
                return(new Dictionary <string, GenericTypeParameterBuilder>(0));
            }

            var name2GenericType = new Dictionary <string, GenericTypeParameterBuilder>(parentEmitter.GenericTypeParams.Length);

            foreach (var genType in parentEmitter.GenericTypeParams)
            {
                name2GenericType.Add(genType.Name, genType);
            }
            return(name2GenericType);
        }
Beispiel #11
0
 public NestedClassEmitter(AbstractTypeEmitter maintype, TypeBuilder typeBuilder)
     : base(typeBuilder)
 {
     maintype.Nested.Add(this);
 }
 internal TypeConstructorEmitter(AbstractTypeEmitter maintype)
     : base(maintype, maintype.TypeBuilder.DefineTypeInitializer())
 {
 }