Example #1
0
        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);
        }