コード例 #1
0
        void MarkCustomAttribute(CustomAttribute ca)
        {
            MarkMethod(ca.Constructor);

            if (!ca.Resolved)
            {
                ca = ca.Clone();
                ca.Resolve();
            }

            if (!ca.Resolved)
            {
                return;
            }

            MarkCustomAttributeParameters(ca);

            TypeReference  constructor_type = ca.Constructor.DeclaringType;
            TypeDefinition type             = constructor_type.Resolve();

            if (type == null)
            {
                throw new ResolutionException(constructor_type);
            }

            MarkCustomAttributeProperties(ca, type);
            MarkCustomAttributeFields(ca, type);
        }
コード例 #2
0
        public static ParameterDefinition CloneParameterDefinition(ParameterDefinition param, MethodDefinition owner)
        {
            var context = owner.Module;
            var np      = new ParameterDefinition(
                param.Name,
                param.Attributes,
                context.Import(param.ParameterType));

            if (param.HasConstant)
            {
                np.Constant = param.Constant;
            }

            if (param.MarshalInfo != null)
            {
                np.MarshalInfo = new MarshalInfo(param.MarshalInfo.NativeType);
            }

            foreach (var ca in param.CustomAttributes)
            {
                np.CustomAttributes.Add(CustomAttribute.Clone(ca, context));
            }

            return(np);
        }
コード例 #3
0
        internal static ParameterDefinition Clone(ParameterDefinition param, ImportContext context)
        {
            ParameterDefinition np = new ParameterDefinition(
                param.Name,
                param.Sequence,
                param.Attributes,
                context.Import(param.ParameterType));

            if (param.HasConstant)
            {
                np.Constant = param.Constant;
            }

            if (param.MarshalSpec != null)
            {
                np.MarshalSpec = param.MarshalSpec;
            }

            foreach (CustomAttribute ca in param.CustomAttributes)
            {
                np.CustomAttributes.Add(CustomAttribute.Clone(ca, context));
            }

            return(np);
        }
コード例 #4
0
        internal static EventDefinition Clone(EventDefinition evt, ImportContext context)
        {
            EventDefinition ne = new EventDefinition(
                evt.Name,
                context.Import(evt.EventType),
                evt.Attributes);

            if (context.GenericContext.Type is TypeDefinition)
            {
                TypeDefinition type = context.GenericContext.Type as TypeDefinition;
                if (evt.AddMethod != null)
                {
                    ne.AddMethod = type.Methods.GetMethod(evt.AddMethod.Name) [0];
                }
                if (evt.InvokeMethod != null)
                {
                    ne.InvokeMethod = type.Methods.GetMethod(evt.InvokeMethod.Name) [0];
                }
                if (evt.RemoveMethod != null)
                {
                    ne.RemoveMethod = type.Methods.GetMethod(evt.RemoveMethod.Name) [0];
                }
            }

            foreach (CustomAttribute ca in evt.CustomAttributes)
            {
                ne.CustomAttributes.Add(CustomAttribute.Clone(ca, context));
            }

            return(ne);
        }
コード例 #5
0
        internal static TypeDefinition Clone(TypeDefinition type, ImportContext context)
        {
            TypeDefinition nt = new TypeDefinition(
                type.Name,
                type.Namespace,
                type.Attributes);

            TypeReference contextType = context.GenericContext.Type;

            context.GenericContext.Type = nt;

            GenericParameter.CloneInto(type, nt, context);

            if (type.BaseType != null)
            {
                nt.BaseType = context.Import(type.BaseType);
            }

            if (type.HasLayoutInfo)
            {
                nt.ClassSize   = type.ClassSize;
                nt.PackingSize = type.PackingSize;
            }

            if (type.HasFields)
            {
                foreach (FieldDefinition field in type.Fields)
                {
                    nt.Fields.Add(FieldDefinition.Clone(field, context));
                }
            }
            if (type.HasConstructors)
            {
                foreach (MethodDefinition ctor in type.Constructors)
                {
                    nt.Constructors.Add(MethodDefinition.Clone(ctor, context));
                }
            }
            if (type.HasMethods)
            {
                foreach (MethodDefinition meth in type.Methods)
                {
                    nt.Methods.Add(MethodDefinition.Clone(meth, context));
                }
            }
            if (type.HasEvents)
            {
                foreach (EventDefinition evt in type.Events)
                {
                    nt.Events.Add(EventDefinition.Clone(evt, context));
                }
            }
            if (type.HasProperties)
            {
                foreach (PropertyDefinition prop in type.Properties)
                {
                    nt.Properties.Add(PropertyDefinition.Clone(prop, context));
                }
            }
            if (type.HasInterfaces)
            {
                foreach (TypeReference intf in type.Interfaces)
                {
                    nt.Interfaces.Add(context.Import(intf));
                }
            }
            if (type.HasNestedTypes)
            {
                foreach (TypeDefinition nested in type.NestedTypes)
                {
                    nt.NestedTypes.Add(Clone(nested, context));
                }
            }
            if (type.HasCustomAttributes)
            {
                foreach (CustomAttribute ca in type.CustomAttributes)
                {
                    nt.CustomAttributes.Add(CustomAttribute.Clone(ca, context));
                }
            }
            if (type.HasSecurityDeclarations)
            {
                foreach (SecurityDeclaration dec in type.SecurityDeclarations)
                {
                    nt.SecurityDeclarations.Add(SecurityDeclaration.Clone(dec));
                }
            }

            context.GenericContext.Type = contextType;

            return(nt);
        }