internal static MethodDefinition Clone(MethodDefinition meth, ImportContext context) { MethodDefinition nm = new MethodDefinition(meth.Name, RVA.Zero, meth.Attributes, meth.ImplAttributes, meth.HasThis, meth.ExplicitThis, meth.CallingConvention); context.GenericContext.Method = nm; foreach (GenericParameter p in meth.GenericParameters) { nm.GenericParameters.Add(GenericParameter.Clone(p, context)); } nm.ReturnType.ReturnType = context.Import(meth.ReturnType.ReturnType); if (meth.ReturnType.HasConstant) { nm.ReturnType.Constant = meth.ReturnType.Constant; } if (meth.ReturnType.MarshalSpec != null) { nm.ReturnType.MarshalSpec = meth.ReturnType.MarshalSpec; } foreach (CustomAttribute ca in meth.ReturnType.CustomAttributes) { nm.ReturnType.CustomAttributes.Add(CustomAttribute.Clone(ca, context)); } if (meth.PInvokeInfo != null) { nm.PInvokeInfo = meth.PInvokeInfo; // TODO: import module ? } foreach (ParameterDefinition param in meth.Parameters) { nm.Parameters.Add(ParameterDefinition.Clone(param, context)); } foreach (MethodReference ov in meth.Overrides) { nm.Overrides.Add(context.Import(ov)); } foreach (CustomAttribute ca in meth.CustomAttributes) { nm.CustomAttributes.Add(CustomAttribute.Clone(ca, context)); } foreach (SecurityDeclaration sec in meth.SecurityDeclarations) { nm.SecurityDeclarations.Add(SecurityDeclaration.Clone(sec)); } if (meth.Body != null) { nm.Body = MethodBody.Clone(meth.Body, nm, context); } return(nm); }
internal static TypeDefinition Clone(TypeDefinition type, ImportContext context) { TypeDefinition nt = new TypeDefinition( type.Name, type.Namespace, type.Attributes); context.GenericContext.Type = nt; foreach (GenericParameter p in type.GenericParameters) { nt.GenericParameters.Add(GenericParameter.Clone(p, context)); } if (type.BaseType != null) { nt.BaseType = context.Import(type.BaseType); } if (type.HasLayoutInfo) { nt.ClassSize = type.ClassSize; nt.PackingSize = type.PackingSize; } foreach (FieldDefinition field in type.Fields) { nt.Fields.Add(FieldDefinition.Clone(field, context)); } foreach (MethodDefinition ctor in type.Constructors) { nt.Constructors.Add(MethodDefinition.Clone(ctor, context)); } foreach (MethodDefinition meth in type.Methods) { nt.Methods.Add(MethodDefinition.Clone(meth, context)); } foreach (EventDefinition evt in type.Events) { nt.Events.Add(EventDefinition.Clone(evt, context)); } foreach (PropertyDefinition prop in type.Properties) { nt.Properties.Add(PropertyDefinition.Clone(prop, context)); } foreach (TypeReference intf in type.Interfaces) { nt.Interfaces.Add(context.Import(intf)); } foreach (TypeDefinition nested in type.NestedTypes) { nt.NestedTypes.Add(Clone(nested, context)); } foreach (CustomAttribute ca in type.CustomAttributes) { nt.CustomAttributes.Add(CustomAttribute.Clone(ca, context)); } foreach (SecurityDeclaration dec in type.SecurityDeclarations) { nt.SecurityDeclarations.Add(SecurityDeclaration.Clone(dec)); } return(nt); }