Exemplo n.º 1
0
        /// <summary>
        /// Clones this type
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        public static TypeDefinition Clone(this TypeDefinition type, MemberImportingSession session)
        {
            var t = new TypeDefinition(type.Namespace, type.Name, type.Attributes, type.BaseType)
            {
                PackingSize   = type.PackingSize,
                ClassSize     = type.ClassSize,
                HasSecurity   = type.HasSecurity,
                MetadataToken = new MetadataToken(type.MetadataToken.TokenType, GlobalContainer.GetFreeRID(session.DestinationModule))
            };

            foreach (var x in type.Interfaces)
            {
                t.Interfaces.Add(x);
            }
            foreach (var x in type.SecurityDeclarations)
            {
                t.SecurityDeclarations.Add(x);
            }
            foreach (var x in type.CustomAttributes)
            {
                t.CustomAttributes.Add(x);
            }
            foreach (var x in type.GenericParameters)
            {
                t.GenericParameters.Add(x);
            }
            return(t);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Clones this property
        /// </summary>
        /// <param name="prop"></param>
        /// <returns></returns>
        public static PropertyDefinition Clone(this PropertyDefinition prop, MemberImportingSession session)
        {
            var p = new PropertyDefinition(prop.Name, prop.Attributes, prop.PropertyType)
            {
                GetMethod     = prop.GetMethod,
                SetMethod     = prop.SetMethod,
                MetadataToken = new MetadataToken(prop.MetadataToken.TokenType, GlobalContainer.GetFreeRID(session.DestinationModule))
            };

            foreach (var x in prop.CustomAttributes)
            {
                p.CustomAttributes.Add(x);
            }
            return(p);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Clones this event
        /// </summary>
        /// <param name="prop"></param>
        /// <returns></returns>
        public static EventDefinition Clone(this EventDefinition evt, MemberImportingSession session)
        {
            var e = new EventDefinition(evt.Name, evt.Attributes, evt.EventType)
            {
                AddMethod     = evt.AddMethod,
                InvokeMethod  = evt.InvokeMethod,
                MetadataToken = new MetadataToken(evt.MetadataToken.TokenType, GlobalContainer.GetFreeRID(session.DestinationModule)),
                RemoveMethod  = evt.RemoveMethod
            };

            foreach (var x in evt.CustomAttributes)
            {
                e.CustomAttributes.Add(x);
            }
            return(e);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Clones this field
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        public static FieldDefinition Clone(this FieldDefinition field, MemberImportingSession session)
        {
            var f = new FieldDefinition(field.Name, field.Attributes, field.FieldType)
            {
                Offset        = field.Offset,
                InitialValue  = field.InitialValue,
                HasConstant   = field.HasConstant,
                Constant      = field.Constant,
                MarshalInfo   = field.MarshalInfo,
                HasDefault    = field.HasDefault,
                MetadataToken = new MetadataToken(field.MetadataToken.TokenType, GlobalContainer.GetFreeRID(session.DestinationModule))
            };

            foreach (var x in field.CustomAttributes)
            {
                f.CustomAttributes.Add(x);
            }
            return(f);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Clones this generic parameter
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        public static GenericParameter Clone(this GenericParameter param, IGenericParameterProvider owner, MemberImportingSession session)
        {
            var p = new GenericParameter(param.Name, owner)
            {
                Attributes    = param.Attributes,
                DeclaringType = param.DeclaringType,
                HasDefaultConstructorConstraint = param.HasDefaultConstructorConstraint,
                MetadataToken = new MetadataToken(param.MetadataToken.TokenType, GlobalContainer.GetFreeRID(session.DestinationModule))
            };

            foreach (var x in param.Constraints)
            {
                p.Constraints.Add(x);
            }
            foreach (var x in param.CustomAttributes)
            {
                p.CustomAttributes.Add(x);
            }
            foreach (var x in param.GenericParameters)
            {
                p.GenericParameters.Add(x);
            }
            return(p);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Clones this method
        /// </summary>
        /// <param name="method"></param>
        /// <returns></returns>
        public static MethodDefinition Clone(this MethodDefinition method, MemberImportingSession session)
        {
            var m = new MethodDefinition(method.Name, method.Attributes, method.ReturnType)
            {
                CallingConvention = method.CallingConvention,
                ExplicitThis      = method.ExplicitThis,
                HasThis           = method.HasThis,
                ImplAttributes    = method.ImplAttributes,
                MetadataToken     = new MetadataToken(method.MetadataToken.TokenType, GlobalContainer.GetFreeRID(session.DestinationModule)),
                MethodReturnType  = method.MethodReturnType,
                PInvokeInfo       = method.PInvokeInfo
            };

            m.IsPInvokeImpl = m.PInvokeInfo != null;
            var body = m.Body;

            body.GetType().GetField("code_size", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(body, method.Body.CodeSize);
            foreach (var x in method.CustomAttributes)
            {
                m.CustomAttributes.Add(x);
            }
            foreach (var x in method.GenericParameters)
            {
                m.GenericParameters.Add(x);
            }
            foreach (var x in method.Overrides)
            {
                m.Overrides.Add(x);
            }
            foreach (var x in method.SecurityDeclarations)
            {
                m.SecurityDeclarations.Add(x);
            }
            return(m);
        }