public FunctionPointerType()
     : base(null)
 {
     this.function = new MethodReference();
     this.function.Name = "method";
     this.etype = MD.ElementType.FnPtr;
 }
        internal MethodSpecification(MethodReference method)
        {
            if (method == null)
                throw new ArgumentNullException("method");

            this.method = method;
            this.token = new MetadataToken(TokenType.MethodSpec);
        }
Пример #3
0
        MethodSpecification ImportMethodSpecification(MethodReference method, ImportGenericContext context)
        {
            if (!method.IsGenericInstance)
                throw new NotSupportedException();

            var instance = (GenericInstanceMethod)method;
            var element_method = ImportMethod(instance.ElementMethod, context);
            var imported_instance = new GenericInstanceMethod(element_method);

            var arguments = instance.GenericArguments;
            var imported_arguments = imported_instance.GenericArguments;

            for (int i = 0; i < arguments.Count; i++)
                imported_arguments.Add(ImportType(arguments[i], context));

            return imported_instance;
        }
Пример #4
0
        public MethodReference ImportMethod(MethodReference method, ImportGenericContext context)
        {
            if (method.IsGenericInstance)
                return ImportMethodSpecification(method, context);

            var declaring_type = ImportType(method.DeclaringType, context);

            var reference = new MethodReference
            {
                Name = method.Name,
                HasThis = method.HasThis,
                ExplicitThis = method.ExplicitThis,
                DeclaringType = declaring_type,
                CallingConvention = method.CallingConvention,
            };

            if (method.HasGenericParameters)
                ImportGenericParameters(reference, method);

            context.Push(reference);
            try
            {
                reference.ReturnType = ImportType(method.ReturnType, context);

                if (!method.HasParameters)
                    return reference;

                var reference_parameters = reference.Parameters;

                var parameters = method.Parameters;
                for (int i = 0; i < parameters.Count; i++)
                    reference_parameters.Add(
                        new ParameterDefinition(ImportType(parameters[i].ParameterType, context)));

                return reference;
            }
            finally
            {
                context.Pop();
            }
        }
Пример #5
0
        public MethodReference ImportMethod(SR.MethodBase method, ImportGenericContext context, ImportGenericKind import_kind)
        {
            if (IsMethodSpecification(method) || ImportOpenGenericMethod(method, import_kind))
                return ImportMethodSpecification(method, context);

            var declaring_type = ImportType(method.DeclaringType, context);

            if (IsGenericInstance(method.DeclaringType))
                method = method.Module.ResolveMethod(method.MetadataToken);

            var reference = new MethodReference
            {
                Name = method.Name,
                HasThis = HasCallingConvention(method, SR.CallingConventions.HasThis),
                ExplicitThis = HasCallingConvention(method, SR.CallingConventions.ExplicitThis),
                DeclaringType = ImportType(method.DeclaringType, context, ImportGenericKind.Definition),
            };

            if (HasCallingConvention(method, SR.CallingConventions.VarArgs))
                reference.CallingConvention &= MethodCallingConvention.VarArg;

            if (method.IsGenericMethod)
                ImportGenericParameters(reference, method.GetGenericArguments());

            context.Push(reference);
            try
            {
                var method_info = method as SR.MethodInfo;
                reference.ReturnType = method_info != null
                    ? ImportType(method_info.ReturnType, context)
                    : ImportType(typeof(void), default(ImportGenericContext));

                var parameters = method.GetParameters();
                var reference_parameters = reference.Parameters;

                for (int i = 0; i < parameters.Length; i++)
                    reference_parameters.Add(
                        new ParameterDefinition(ImportType(parameters[i].ParameterType, context)));

                reference.DeclaringType = declaring_type;

                return reference;
            }
            finally
            {
                context.Pop();
            }
        }
 public GenericInstanceMethod(MethodReference method)
     : base(method)
 {
 }
Пример #7
0
 internal CallSite()
 {
     this.signature = new MethodReference();
     this.signature.token = new MetadataToken(TokenType.Signature, 0);
 }
        public static MethodDefinition GetMethod(Collection<MethodDefinition> methods, MethodReference reference)
        {
            for (int i = 0; i < methods.Count; i++)
            {
                var method = methods[i];

                if (method.Name != reference.Name)
                    continue;

                if (method.HasGenericParameters != reference.HasGenericParameters)
                    continue;

                if (method.HasGenericParameters && method.GenericParameters.Count != reference.GenericParameters.Count)
                    continue;

                if (!AreSame(method.ReturnType, reference.ReturnType))
                    continue;

                if (method.HasParameters != reference.HasParameters)
                    continue;

                if (!method.HasParameters && !reference.HasParameters)
                    return method;

                if (!AreSame(method.Parameters, reference.Parameters))
                    continue;

                return method;
            }

            return null;
        }
        MethodDefinition GetMethod(TypeDefinition type, MethodReference reference)
        {
            while (type != null)
            {
                var method = GetMethod(type.Methods, reference);
                if (method != null)
                    return method;

                if (type.BaseType == null)
                    return null;

                type = Resolve(type.BaseType);
            }

            return null;
        }
        public virtual MethodDefinition Resolve(MethodReference method)
        {
            if (method == null)
                throw new ArgumentNullException("method");

            var type = Resolve(method.DeclaringType);
            if (type == null)
                return null;

            method = method.GetElementMethod();

            if (!type.HasMethods)
                return null;

            return GetMethod(type, method);
        }
Пример #11
0
        /// <summary>
        /// Determines if two methods matches
        /// </summary>
        /// <param name="mref1">a method</param>
        /// <param name="mref2">a method to compare</param>
        /// <returns>true if matches</returns>
        private static bool MethodMatches(MethodReference mref1, MethodReference mref2)
        {
            if ((mref1.Name != mref2.Name) || (mref1.Parameters.Count != mref2.Parameters.Count) ||
                (mref1.ReturnType.FullName != mref2.ReturnType.FullName))
                return false;

            for (var i = 0; i <= mref1.Parameters.Count - 1; i++)
            {
                if (mref1.Parameters[i].ParameterType.FullName != mref2.Parameters[i].ParameterType.FullName)
                    return false;
            }
            return true;
        }
Пример #12
0
        private static MethodReference FixMethodImport(ModuleDefinition context, MethodDefinition source,
            MethodDefinition target, MethodReference method)
        {
            if (method.DeclaringType.FullName == source.DeclaringType.FullName)
                return FindMatchingMethod(target.DeclaringType, method);

            return context.Import(method);
        }
Пример #13
0
 /// <summary>
 /// Find a similar method in the given type definition 
 /// </summary>
 /// <param name="tdef">Type definition</param>
 /// <param name="mref">Method reference</param>
 /// <returns>Method definition (or null if not found)</returns>
 public static MethodDefinition FindMatchingMethod(TypeDefinition tdef, MethodReference mref)
 {
     return tdef.Methods.FirstOrDefault(mdef => MethodMatches(mdef, mref));
 }
 internal CustomAttribute(uint signature, MethodReference constructor)
 {
     this.signature = signature;
     this.constructor = constructor;
     this.resolved = false;
 }
 public CustomAttribute(MethodReference constructor, byte[] blob)
 {
     this.constructor = constructor;
     this.resolved = false;
     this.blob = blob;
 }
 public CustomAttribute(MethodReference constructor)
 {
     this.constructor = constructor;
     this.resolved = true;
 }