예제 #1
0
        bool?CanAccess(TypeDef td, GenericInstSig git, MemberRef mr)
        {
            if (mr == null || td == null)
            {
                return(null);
            }

            if (mr.MethodSig != null)
            {
                var md = td.FindMethodCheckBaseType(mr.Name, mr.MethodSig);
                if (md == null)
                {
                    // Assume that it's an array type if it's one of these methods
                    if (mr.Name == "Get" || mr.Name == "Set" || mr.Name == "Address" || mr.Name == ".ctor")
                    {
                        return(true);
                    }
                    return(null);
                }
                return(CanAccess(md, git));
            }

            if (mr.FieldSig != null)
            {
                return(CanAccess(td.FindFieldCheckBaseType(mr.Name, mr.FieldSig), git));
            }

            return(null);
        }
예제 #2
0
        IMethod ResolveMethod_Helper(ITypeDefOrRef declaringType, MethodData data)
        {
            TypeDef   declaringDef = declaringType.ResolveTypeDefThrow();
            MethodSig methodSig    = GetMethodSig(data);

            // Has a GenericMVar
            if (data.HasGenericArguments)
            {
                MethodSig detectedSig = null;
                MethodDef method      = FindMethodCheckBaseType(declaringType, data, out detectedSig);

                if (method == null || detectedSig == null)
                {
                    throw new Exception(String.Format(
                                            "Unable to find generic method from the declaring/base types: DeclaringType={0}, MethodName={1}, MethodSig={2}",
                                            declaringType.ReflectionFullName, data.Name, methodSig));
                }

                MethodSpec methodSpec = new MethodSpecUser(method, ToGenericInstMethodSig(data));
                return(this.Importer.Import(methodSpec));
            }
            else             // No GenericMVars
            {
                MethodDef method = declaringDef.FindMethodCheckBaseType(data.Name, methodSig);
                if (method == null)
                {
                    throw new Exception(String.Format(
                                            "Unable to find method from the declaring/base types: DeclaringType={0}, MethodName={1}, MethodSig={2}",
                                            declaringType.ReflectionFullName, data.Name, methodSig));
                }

                return(this.Importer.Import(method));
            }
        }
예제 #3
0
        /// <summary>
        /// Find a MethodDef from a declaring type and some MethodData. Will generate
        /// a list of possible MethodSigs and check against each of them, returning the
        /// first-found MethodDef that matches the method name and signature.
        /// </summary>
        /// <param name="declaringType">Declaring type</param>
        /// <param name="data">MethodData</param>
        /// <param name="detectedSig">The detected MethodSig</param>
        /// <returns>MethodDef if found, null if none found</returns>
        MethodDef FindMethodCheckBaseType(ITypeDefOrRef declaringType, MethodData data, out MethodSig detectedSig)
        {
            detectedSig = null;

            TypeDef declaringDef = declaringType.ResolveTypeDef();

            if (declaringDef == null)
            {
                return(null);
            }

            MethodDef method       = null;
            MethodSig methodSig    = GetMethodSig(data);
            var       possibleSigs = PossibleMethodSigs(declaringType, methodSig, data);

            detectedSig = possibleSigs.FirstOrDefault(sig => {
                return((method = declaringDef.FindMethodCheckBaseType(data.Name, sig)) != null);
            });

            return(method);
        }
예제 #4
0
		bool? CanAccess(TypeDef td, GenericInstSig git, MemberRef mr) {
			if (mr == null || td == null)
				return null;

			if (mr.MethodSig != null) {
				var md = td.FindMethodCheckBaseType(mr.Name, mr.MethodSig);
				if (md == null) {
					// Assume that it's an array type if it's one of these methods
					if (mr.Name == "Get" || mr.Name == "Set" || mr.Name == "Address" || mr.Name == ".ctor")
						return true;
					return null;
				}
				return CanAccess(md, git);
			}

			if (mr.FieldSig != null)
				return CanAccess(td.FindFieldCheckBaseType(mr.Name, mr.FieldSig), git);

			return null;
		}
예제 #5
0
 public static MethodDef GetDefinition(this TypeDef type, MethodSignature method) => type.FindMethodCheckBaseType(method.Name, type.Module.ToSig(method), ComparerOptions, type.Module);