GetPredefinedConstructor() public static méthode

public static GetPredefinedConstructor ( System.TypeSpec t, Mono.CSharp.Location loc ) : MethodSpec
t System.TypeSpec
loc Mono.CSharp.Location
Résultat MethodSpec
        public override void ApplyAttributes(MethodBuilder mb, ConstructorBuilder cb, int index)
        {
            base.ApplyAttributes(mb, cb, index);

            CustomAttributeBuilder ca = TypeManager.param_array_attr;

            if (ca == null)
            {
                ConstructorInfo ci = TypeManager.GetPredefinedConstructor(TypeManager.param_array_type, Location, Type.EmptyTypes);
                if (ci == null)
                {
                    return;
                }

                ca = new CustomAttributeBuilder(ci, new object [0]);
                if (ca == null)
                {
                    return;
                }

                TypeManager.param_array_attr = ca;
            }

            builder.SetCustomAttribute(ca);
        }
Exemple #2
0
        public override void Emit(TypeContainer tc)
        {
            base.Emit(tc);

            if (has_extension_method)
            {
                PredefinedAttributes.Get.Extension.EmitAttribute(Builder);
            }

            // FIXME: Does this belong inside SRE.AssemblyBuilder instead?
            PredefinedAttribute pa = PredefinedAttributes.Get.RuntimeCompatibility;

            if (pa.IsDefined && (OptAttributes == null || !OptAttributes.Contains(pa)))
            {
                ConstructorInfo ci = TypeManager.GetPredefinedConstructor(
                    pa.Type, Location.Null, Type.EmptyTypes);
                PropertyInfo [] pis = new PropertyInfo [1];
                pis [0] = TypeManager.GetPredefinedProperty(pa.Type,
                                                            "WrapNonExceptionThrows", Location.Null, TypeManager.bool_type);
                object [] pargs = new object [1];
                pargs [0] = true;
                Builder.SetCustomAttribute(new CustomAttributeBuilder(ci, new object [0], pis, pargs));
            }

            if (declarative_security != null)
            {
                MethodInfo add_permission   = typeof(AssemblyBuilder).GetMethod("AddPermissionRequests", BindingFlags.Instance | BindingFlags.NonPublic);
                object     builder_instance = Builder;

                try {
                    // Microsoft runtime hacking
                    if (add_permission == null)
                    {
                        Type assembly_builder = typeof(AssemblyBuilder).Assembly.GetType("System.Reflection.Emit.AssemblyBuilderData");
                        add_permission = assembly_builder.GetMethod("AddPermissionRequests", BindingFlags.Instance | BindingFlags.NonPublic);

                        FieldInfo fi = typeof(AssemblyBuilder).GetField("m_assemblyData", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
                        builder_instance = fi.GetValue(Builder);
                    }

                    object[] args = new object [] { declarative_security [SecurityAction.RequestMinimum],
                                                    declarative_security [SecurityAction.RequestOptional],
                                                    declarative_security [SecurityAction.RequestRefuse] };
                    add_permission.Invoke(builder_instance, args);
                }
                catch {
                    Report.RuntimeMissingSupport(Location.Null, "assembly permission setting");
                }
            }
        }
Exemple #3
0
        void EmitDecimalConstant()
        {
            ConstructorInfo ctor = TypeManager.decimal_constant_attribute_ctor;

            if (ctor == null)
            {
                if (TypeManager.decimal_constant_attribute_type == null)
                {
                    TypeManager.decimal_constant_attribute_type = TypeManager.CoreLookupType(
                        "System.Runtime.CompilerServices", "DecimalConstantAttribute", Kind.Class, true);

                    if (TypeManager.decimal_constant_attribute_type == null)
                    {
                        return;
                    }
                }

                ctor = TypeManager.GetPredefinedConstructor(TypeManager.decimal_constant_attribute_type, Location,
                                                            TypeManager.byte_type, TypeManager.byte_type,
                                                            TypeManager.uint32_type, TypeManager.uint32_type, TypeManager.uint32_type);

                if (ctor == null)
                {
                    return;
                }

                TypeManager.decimal_constant_attribute_ctor = ctor;
            }

            Decimal d = ((DecimalConstant)value).Value;

            int []    bits = Decimal.GetBits(d);
            object [] args = new object [] {
                (byte)(bits [3] >> 16),
                (byte)(bits [3] >> 31),
                (uint)bits [2], (uint)bits [1], (uint)bits [0]
            };

            CustomAttributeBuilder cab = new CustomAttributeBuilder(ctor, args);

            FieldBuilder.SetCustomAttribute(cab);
        }
Exemple #4
0
        public override void Emit()
        {
            if (OptAttributes != null)
            {
                OptAttributes.Emit();
            }

            if (is_unsafe)
            {
                Type t = TypeManager.CoreLookupType(context, "System.Security", "UnverifiableCodeAttribute", Kind.Class, true);
                if (t != null)
                {
                    ConstructorInfo unverifiable_code_ctor = TypeManager.GetPredefinedConstructor(t, Location.Null, Type.EmptyTypes);
                    if (unverifiable_code_ctor != null)
                    {
                        Builder.SetCustomAttribute(new CustomAttributeBuilder(unverifiable_code_ctor, new object [0]));
                    }
                }
            }
        }