bool CalculateHasTypeEquivalence() { if (BaseType?.HasTypeEquivalence == true) { return(true); } if (TIAHelper.IsTypeDefEquivalent(this)) { return(true); } var hash = GetAllInterfaces(this); foreach (var ifaceType in hash) { if (ifaceType.HasTypeEquivalence) { ObjectPools.Free(ref hash); return(true); } } ObjectPools.Free(ref hash); return(false); }
protected override IEnumerable <AnalyzerTreeNodeData> FetchChildren(CancellationToken ct) { foundMethods = new ConcurrentDictionary <MethodDef, int>(); AddTypeEquivalentTypes(Context.DocumentService, analyzedType, analyzedTypes); IEnumerable <(ModuleDef module, ITypeDefOrRef type)> modules; if (includeAllModules) { modules = GetAllModules(analyzedType.Module, ct); } else if (TIAHelper.IsTypeDefEquivalent(analyzedType)) { modules = GetTypeEquivalentModulesAndTypes(analyzedTypes); } else if (IsPublic(analyzedType)) { modules = GetReferencingModules(analyzedType.Module, ct); } else { modules = GetModuleAndAnyFriends(analyzedType.Module, ct); } var results = modules.AsParallel().WithCancellation(ct).SelectMany(a => FindReferencesInModule(new[] { a.Item1 }, a.Item2, ct)); foreach (var result in results) { yield return(result); } foundMethods = null; }
static IEnumerable <TypeDef> GetTypeEquivalentTypes(AssemblyDef?assembly, ModuleDef?module, TypeDef type) { Debug.Assert(TIAHelper.IsTypeDefEquivalent(type)); var typeRef = new ModuleDefUser("dummy").Import(type); foreach (var mod in GetModules(assembly, module)) { var otherType = mod.Find(typeRef); if (otherType != type && TIAHelper.IsTypeDefEquivalent(otherType) && new SigComparer().Equals(otherType, type) && !new SigComparer(SigComparerOptions.DontCheckTypeEquivalence).Equals(otherType, type)) { yield return(otherType); } } }
internal static void AddTypeEquivalentTypes(IDsDocumentService documentService, TypeDef analyzedType, List <TypeDef> analyzedTypes) { Debug.Assert(analyzedTypes.Count == 1 && analyzedTypes[0] == analyzedType); if (!TIAHelper.IsTypeDefEquivalent(analyzedType)) { return; } foreach (var document in documentService.GetDocuments()) { foreach (var type in GetTypeEquivalentTypes(document.AssemblyDef, document.ModuleDef, analyzedType)) { if (type != analyzedType) { analyzedTypes.Add(type); } } } }
IEnumerable <T> FindReferencesGlobal(CancellationToken ct) { IEnumerable <ModuleDef> modules; if (TIAHelper.IsTypeDefEquivalent(analyzedType)) { var analyzedTypes = new List <TypeDef> { analyzedType }; SearchNode.AddTypeEquivalentTypes(documentService, analyzedType, analyzedTypes); modules = SearchNode.GetTypeEquivalentModules(analyzedTypes); } else { modules = GetReferencingModules(analyzedType.Module, ct); } allModules.AddRange(modules); return(allModules.AsParallel().WithCancellation(ct).SelectMany(a => FindReferencesInModule(a, ct))); }
IEnumerable <T> FindReferencesInAssemblyAndFriends(CancellationToken ct) { IEnumerable <ModuleDef> modules; if (includeAllModules) { modules = documentService.GetDocuments().Select(a => a.ModuleDef).OfType <ModuleDef>(); } else if (TIAHelper.IsTypeDefEquivalent(analyzedType)) { var analyzedTypes = new List <TypeDef> { analyzedType }; SearchNode.AddTypeEquivalentTypes(documentService, analyzedType, analyzedTypes); modules = SearchNode.GetTypeEquivalentModules(analyzedTypes); } else { modules = GetModuleAndAnyFriends(analyzedType.Module, ct); } allModules.AddRange(modules); return(allModules.AsParallel().WithCancellation(ct).SelectMany(a => FindReferencesInModule(a, ct))); }
IEnumerable <T> FindReferencesGlobal(CancellationToken ct) { IEnumerable <ModuleDef> modules; if ((options & ScopedWhereUsedAnalyzerOptions.IncludeAllModules) != 0) { modules = documentService.GetDocuments().Select(a => a.ModuleDef).OfType <ModuleDef>(); } else if (TIAHelper.IsTypeDefEquivalent(analyzedType)) { var analyzedTypes = new List <TypeDef> { analyzedType }; SearchNode.AddTypeEquivalentTypes(documentService, analyzedType, analyzedTypes); modules = SearchNode.GetTypeEquivalentModules(analyzedTypes); } else { modules = GetReferencingModules(analyzedType.Module, ct); } allModules.AddRange(modules); return(allModules.AsParallel().WithCancellation(ct).SelectMany(a => FindReferencesInModule(a, ct))); }