Пример #1
0
        IEnumerable <AnalyzerTreeNodeData> FindReferencesInModule(IEnumerable <ModuleDef> modules, ITypeDefOrRef tr, CancellationToken ct)
        {
            var trScopeType = tr.GetScopeType();
            var checkedAsms = new HashSet <AssemblyDef>();

            foreach (var module in modules)
            {
                if ((usage & AttributeTargets.Assembly) != 0)
                {
                    AssemblyDef asm = module.Assembly;
                    if (!(asm is null) && checkedAsms.Add(asm))
                    {
                        foreach (var attribute in asm.GetCustomAttributes())
                        {
                            if (new SigComparer().Equals(attribute.AttributeType?.GetScopeType(), trScopeType))
                            {
                                yield return(new AssemblyNode(asm)
                                {
                                    Context = Context
                                });

                                break;
                            }
                        }
                    }
                }

                ct.ThrowIfCancellationRequested();

                if ((usage & AttributeTargets.Module) != 0)
                {
                    foreach (var attribute in module.GetCustomAttributes())
                    {
                        if (new SigComparer().Equals(attribute.AttributeType?.GetScopeType(), trScopeType))
                        {
                            yield return(new ModuleNode(module)
                            {
                                Context = Context
                            });

                            break;
                        }
                    }
                }

                ct.ThrowIfCancellationRequested();

                if ((usage & (AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.GenericParameter | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.ReturnValue | AttributeTargets.Parameter)) != 0)
                {
                    foreach (TypeDef type in TreeTraversal.PreOrder(module.Types, t => t.NestedTypes))
                    {
                        ct.ThrowIfCancellationRequested();
                        foreach (var result in FindReferencesWithinInType(type, tr))
                        {
                            ct.ThrowIfCancellationRequested();
                            yield return(result);
                        }
                    }
                }
            }
        }