public MethodMeta Resolve(MethodReference methodRef) { string methodName = methodRef.Name; int targetParametersCount = methodRef.Parameters.Count; bool hasAMatchingMethod = false; for (int i = 0, max = this.methods.Length; i < max; ++i) { MethodMeta method = this.methods[i]; if (method.Name == methodName) { hasAMatchingMethod = true; if (targetParametersCount == method.ParametersType.Length) { int j = 0; for (; j < targetParametersCount; ++j) { TypeReference paramType = methodRef.Parameters[j].ParameterType; string targetParameterType = method.ParametersType[j]; if (paramType.IsGenericParameter == true || paramType.ContainsGenericParameter == true) { if (paramType.FullName.Replace("!!0", "T").Replace("!0", "T") != method.ParametersType[j]) { break; } } else if (paramType.FullName != targetParameterType) { break; } } if (j == targetParametersCount) { return(method); // Due to inheritage, checking accessor might be cumbersome to resolve. (I am being lazy) //if (method.IsPublic == true || this.root.IsFriend(methodRef.Module.Assembly.Name.Name) == true) //{ // Console.WriteLine("Found Method " + method + " " + method.IsPublic + " " + methodRef.Module.Assembly.Name.Name); // return method; //} //break; } } } } // Return a method with an unmatch message. if (hasAMatchingMethod == true) { return(new MethodMeta(methodRef, "Method signature does not exist, but an overload is available.")); } return(null); }
public void ResolveReferences(ICollection <TypeReference> types, ICollection <FieldReference> fields, ICollection <MethodReference> methods) { int assembliesMetaLength = this.unityMeta.AssembliesMeta.Length; DynamicOrderedArray <AssemblyMeta> assemblies = new DynamicOrderedArray <AssemblyMeta>(this.unityMeta.AssembliesMeta); foreach (TypeReference typeRef in types) { TypeMeta meta = null; int j = 0; for (; j < assembliesMetaLength && meta == null; ++j) { meta = assemblies.array[j].Resolve(typeRef); } if (meta != null) { assemblies.BringToTop(j - 1); if (meta.ErrorMessage != null) { this.foundTypes.Add(meta); } } else { // Type not found, maybe look into other types. Might be renamed. TypeMeta lastFound = null; string typeRefNamespace = typeRef.Namespace; string typeRefName = typeRef.Name; j = 0; for (; j < assembliesMetaLength && lastFound == null; ++j) { for (int k = 0, max = assemblies.array[j].Types.Length; k < max; ++k) { TypeMeta typeMeta = assemblies.array[j].Types[k]; if (typeMeta.Name == typeRefName) { if (lastFound == null || this.GetLevenshteinDistance(lastFound.Namespace, typeRefNamespace) > this.GetLevenshteinDistance(typeMeta.Namespace, typeRefNamespace)) { lastFound = typeMeta; break; } } } } if (lastFound != null) { this.missingTypes.Add(new TypeMeta(typeRef, "Type not found, but a similar Type has been found at \"" + lastFound.FullName + "\".")); } else { this.missingTypes.Add(new TypeMeta(typeRef)); } } } foreach (FieldReference fieldRef in fields) { FieldMeta meta = null; int j = 0; for (; j < assembliesMetaLength && meta == null; ++j) { meta = assemblies.array[j].Resolve(fieldRef); } if (meta != null) { assemblies.BringToTop(j - 1); if (meta.ErrorMessage != null) { this.foundFields.Add(meta); } } else { this.missingFields.Add(new FieldMeta(fieldRef)); } } foreach (MethodReference methodRef in methods) { MethodMeta meta = null; int j = 0; for (; j < assembliesMetaLength && meta == null; ++j) { meta = assemblies.array[j].Resolve(methodRef); } if (meta != null) { assemblies.BringToTop(j - 1); if (meta.ErrorMessage != null) { this.foundMethods.Add(meta); } } else { this.missingMethods.Add(new MethodMeta(methodRef)); } } }
public int RegisterMethod(MethodMeta meta) { return(this.methodTable.Register(meta)); }