public IEnumerable <ISymbol> Analyze(ISymbol analyzedSymbol, AnalyzerContext context) { Debug.Assert(analyzedSymbol is IField); var scope = context.GetScopeOf((IEntity)analyzedSymbol); foreach (var type in scope.GetTypesInScope(context.CancellationToken)) { var mappingInfo = context.Language.GetCodeMappingInfo(type.ParentModule.PEFile, type.MetadataToken); var methods = type.GetMembers(m => m is IMethod, Options).OfType <IMethod>(); foreach (var method in methods) { if (IsUsedInMethod((IField)analyzedSymbol, method, mappingInfo, context)) { yield return(method); } } foreach (var property in type.Properties) { if (property.CanGet && IsUsedInMethod((IField)analyzedSymbol, property.Getter, mappingInfo, context)) { yield return(property); continue; } if (property.CanSet && IsUsedInMethod((IField)analyzedSymbol, property.Setter, mappingInfo, context)) { yield return(property); continue; } } foreach (var @event in type.Events) { if (@event.CanAdd && IsUsedInMethod((IField)analyzedSymbol, @event.AddAccessor, mappingInfo, context)) { yield return(@event); continue; } if (@event.CanRemove && IsUsedInMethod((IField)analyzedSymbol, @event.RemoveAccessor, mappingInfo, context)) { yield return(@event); continue; } if (@event.CanInvoke && IsUsedInMethod((IField)analyzedSymbol, @event.InvokeAccessor, mappingInfo, context)) { yield return(@event); continue; } } } }
public IEnumerable <ISymbol> Analyze(ISymbol analyzedSymbol, AnalyzerContext context) { Debug.Assert(analyzedSymbol is ITypeDefinition); var scope = context.GetScopeOf((ITypeDefinition)analyzedSymbol); foreach (var type in scope.GetTypesInScope(context.CancellationToken)) { foreach (var result in ScanType((ITypeDefinition)analyzedSymbol, type, context)) { yield return(result); } } }
public IEnumerable <ISymbol> Analyze(ISymbol analyzedSymbol, AnalyzerContext context) { Debug.Assert(analyzedSymbol is IMethod); var scope = context.GetScopeOf((IEntity)analyzedSymbol); foreach (var type in scope.GetTypesInScope(context.CancellationToken)) { foreach (var result in AnalyzeType((IMethod)analyzedSymbol, type)) { yield return(result); } } }
public IEnumerable <ISymbol> Analyze(ISymbol analyzedSymbol, AnalyzerContext context) { if (!(analyzedSymbol is ITypeDefinition attributeType)) { return(Array.Empty <ISymbol>()); } var scope = context.GetScopeOf(attributeType); // TODO: DeclSecurity attributes are not supported. if (!IsBuiltinAttribute(attributeType, out var knownAttribute)) { return(HandleCustomAttribute(attributeType, scope)); } else { return(HandleBuiltinAttribute(knownAttribute, scope).SelectMany(s => s)); } }
public IEnumerable <ISymbol> Analyze(ISymbol analyzedSymbol, AnalyzerContext context) { Debug.Assert(analyzedSymbol is ITypeDefinition); var analyzedType = (ITypeDefinition)analyzedSymbol; var scope = context.GetScopeOf(analyzedType); context.SortResults = true; return(scope.GetModulesInScope(context.CancellationToken) .AsParallel().AsOrdered() .SelectMany(AnalyzeModuleAndFilter)); IEnumerable <ISymbol> AnalyzeModuleAndFilter(PEFile module) { return(AnalyzeModule(analyzedType, scope, module) .Distinct() .Where(s => !analyzedType.Equals((s as IEntity)?.DeclaringTypeDefinition))); } }
public IEnumerable <ISymbol> Analyze(ISymbol analyzedSymbol, AnalyzerContext context) { if (!(analyzedSymbol is IEntity attributeEntity)) { yield break; } var scope = context.GetScopeOf(attributeEntity); var genericContext = new GenericContext(); // type arguments do not matter for this analyzer. foreach (var module in scope.GetAllModules()) { var ts = new DecompilerTypeSystem(module, module.GetAssemblyResolver()); var referencedParameters = new HashSet <ParameterHandle>(); foreach (var h in module.Metadata.CustomAttributes) { var customAttribute = module.Metadata.GetCustomAttribute(h); var attributeCtor = ts.MainModule.ResolveMethod(customAttribute.Constructor, genericContext); if (attributeCtor.DeclaringTypeDefinition != null && attributeCtor.ParentModule.PEFile == attributeEntity.ParentModule.PEFile && attributeCtor.DeclaringTypeDefinition.MetadataToken == attributeEntity.MetadataToken) { if (customAttribute.Parent.Kind == HandleKind.Parameter) { referencedParameters.Add((ParameterHandle)customAttribute.Parent); } else { var parent = GetParentEntity(ts, customAttribute); if (parent != null) { yield return(parent); } } } } if (referencedParameters.Count > 0) { foreach (var h in module.Metadata.MethodDefinitions) { var md = module.Metadata.GetMethodDefinition(h); foreach (var p in md.GetParameters()) { if (referencedParameters.Contains(p)) { var method = ts.MainModule.ResolveMethod(h, genericContext); if (method != null) { if (method.IsAccessor) { yield return(method.AccessorOwner); } else { yield return(method); } } break; } } } } } }