예제 #1
0
        internal static MethodSignatureDescriptor ExtractMethodSignature(SignatureBlob methodSignatureBlob, MetadataOnlyModule resolver, GenericContext context)
        {
            byte[] signatureAsByteArray = methodSignatureBlob.GetSignatureAsByteArray();
            int    num = 0;
            MethodSignatureDescriptor methodSignatureDescriptor = new MethodSignatureDescriptor()
            {
                ReturnParameter       = new TypeSignatureDescriptor(),
                GenericParameterCount = 0,
                CallingConvention     = SignatureUtil.ExtractCallingConvention(signatureAsByteArray, ref num)
            };
            bool callingConvention = (methodSignatureDescriptor.CallingConvention & Microsoft.MetadataReader.CorCallingConvention.ExplicitThis) != Microsoft.MetadataReader.CorCallingConvention.Default;

            if ((methodSignatureDescriptor.CallingConvention & Microsoft.MetadataReader.CorCallingConvention.Generic) != Microsoft.MetadataReader.CorCallingConvention.Default)
            {
                int num1 = SignatureUtil.ExtractInt(signatureAsByteArray, ref num);
                if (num1 <= 0)
                {
                    CultureInfo invariantCulture         = CultureInfo.InvariantCulture;
                    object[]    invalidMetadataSignature = new object[] { MetadataStringTable.InvalidMetadataSignature, MetadataStringTable.ExpectedPositiveNumberOfGenericParameters };
                    throw new ArgumentException(string.Format(invariantCulture, "{0} {1}", invalidMetadataSignature));
                }
                context = context.VerifyAndUpdateMethodArguments(num1);
                methodSignatureDescriptor.GenericParameterCount = num1;
            }
            int             num2           = SignatureUtil.ExtractInt(signatureAsByteArray, ref num);
            bool            flag           = false;
            CustomModifiers customModifier = SignatureUtil.ExtractCustomModifiers(signatureAsByteArray, ref num, resolver, context);

            methodSignatureDescriptor.ReturnParameter = SignatureUtil.ExtractType(signatureAsByteArray, ref num, resolver, context, flag);
            methodSignatureDescriptor.ReturnParameter.CustomModifiers = customModifier;
            if (callingConvention)
            {
                SignatureUtil.ExtractType(signatureAsByteArray, ref num, resolver, context);
                num2--;
            }
            methodSignatureDescriptor.Parameters = new TypeSignatureDescriptor[num2];
            for (int i = 0; i < num2; i++)
            {
                customModifier = SignatureUtil.ExtractCustomModifiers(signatureAsByteArray, ref num, resolver, context);
                methodSignatureDescriptor.Parameters[i] = SignatureUtil.ExtractType(signatureAsByteArray, ref num, resolver, context, flag);
                methodSignatureDescriptor.Parameters[i].CustomModifiers = customModifier;
            }
            if (num != (int)signatureAsByteArray.Length)
            {
                CultureInfo cultureInfo = CultureInfo.InvariantCulture;
                object[]    objArray    = new object[] { MetadataStringTable.InvalidMetadataSignature, MetadataStringTable.ExtraInformationAfterLastParameter };
                throw new ArgumentException(string.Format(cultureInfo, "{0} {1}", objArray));
            }
            return(methodSignatureDescriptor);
        }
예제 #2
0
 public MetadataOnlyMethodInfo(MetadataOnlyMethodInfo method)
 {
     this.m_resolver         = method.m_resolver;
     this.m_methodDef        = method.m_methodDef;
     this.m_tOwner           = method.m_tOwner;
     this.m_descriptor       = method.m_descriptor;
     this.m_name             = method.m_name;
     this.m_attrs            = method.m_attrs;
     this.m_returnParameter  = method.m_returnParameter;
     this.m_methodBody       = method.m_methodBody;
     this.m_declaringTypeDef = method.m_declaringTypeDef;
     this.m_sigBlob          = method.m_sigBlob;
     this.m_typeArgs         = method.m_typeArgs;
     this.m_methodArgs       = method.m_methodArgs;
     this.m_context          = method.m_context;
     this.m_fullyInitialized = method.m_fullyInitialized;
 }
예제 #3
0
        private void Initialize()
        {
            Type type = null;

            Type[] mTypeArgs = null;
            if (this.m_declaringTypeDef.IsNil)
            {
                mTypeArgs = this.m_typeArgs;
            }
            else
            {
                this.GetOwnerTypeAndTypeArgs(out type, out mTypeArgs);
            }
            GenericContext            genericContext            = new GenericContext(mTypeArgs, this.GetGenericMethodArgs());
            MethodSignatureDescriptor methodSignatureDescriptor = SignatureUtil.ExtractMethodSignature(this.m_sigBlob, this.m_resolver, genericContext);

            this.m_tOwner           = type;
            this.m_context          = genericContext;
            this.m_descriptor       = methodSignatureDescriptor;
            this.m_fullyInitialized = true;
        }
예제 #4
0
        public static MethodBase FindMatchingMethod(string methodName, Type typeToInspect, MethodSignatureDescriptor expectedSignature, GenericContext context)
        {
            bool flag = (methodName.Equals(".ctor", StringComparison.Ordinal) ? true : methodName.Equals(".cctor", StringComparison.Ordinal));
            int  genericParameterCount            = expectedSignature.GenericParameterCount;
            IEnumerable <MethodBase> methodBases  = null;
            MethodFilter             methodFilter = new MethodFilter(methodName, genericParameterCount, (int)expectedSignature.Parameters.Length, expectedSignature.CallingConvention);

            methodBases = (!flag ? SignatureComparer.FilterMethods(methodFilter, typeToInspect.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) : SignatureComparer.FilterConstructors(methodFilter, typeToInspect.GetConstructors(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)));
            MethodBase methodBase = null;
            bool       flag1      = false;

            foreach (MethodBase methodBase1 in methodBases)
            {
                MethodBase methodBase2 = methodBase1;
                bool       flag2       = false;
                if (genericParameterCount > 0 && (int)context.MethodArgs.Length > 0)
                {
                    methodBase2 = (methodBase1 as MethodInfo).MakeGenericMethod(context.MethodArgs);
                    flag2       = true;
                }
                MethodBase templateMethod = null;
                if (!typeToInspect.IsGenericType)
                {
                    templateMethod = (!flag2 ? methodBase2 : methodBase1);
                }
                else
                {
                    templateMethod = SignatureComparer.GetTemplateMethod(typeToInspect, methodBase2.MetadataToken);
                }
                if (!flag && !expectedSignature.ReturnParameter.Type.Equals((templateMethod as MethodInfo).ReturnType) || !SignatureComparer.IsParametersTypeMatch(templateMethod, expectedSignature.Parameters))
                {
                    continue;
                }
                if (flag1)
                {
                    throw new AmbiguousMatchException();
                }
                methodBase = methodBase2;
                flag1      = true;
            }
            return(methodBase);
        }