public static TypeDefinition?GetTypeByDocumentationSignature(AssemblyDefinition assembly, string signature, ITryResolveMetadata resolver)
        {
            int index   = 0;
            var results = new List <IMemberDefinition> ();

            DocumentationSignatureParser.ParseSignaturePart(signature, ref index, assembly.MainModule, DocumentationSignatureParser.MemberType.Type, results, resolver);
            Debug.Assert(results.Count <= 1);
            return(results.Count == 0 ? null : (TypeDefinition)results[0]);
        }
        public static IEnumerable <IMemberDefinition> GetMembersByDocumentationSignature(TypeDefinition type, string signature, ITryResolveMetadata resolver, bool acceptName = false)
        {
            int index       = 0;
            var results     = new List <IMemberDefinition> ();
            var nameBuilder = new StringBuilder();

            var(name, arity) = DocumentationSignatureParser.ParseTypeOrNamespaceName(signature, ref index, nameBuilder);
            DocumentationSignatureParser.GetMatchingMembers(signature, ref index, type.Module, type, name, arity, DocumentationSignatureParser.MemberType.All, results, resolver, acceptName);
            return(results);
        }
        IEnumerable <(SuppressMessageInfo Info, ICustomAttributeProvider Target)> DecodeGlobalSuppressions(ModuleDefinition module, ICustomAttributeProvider provider)
        {
            var attributes = _context.CustomAttributes.GetCustomAttributes(provider).
                             Where(a => TypeRefHasUnconditionalSuppressions(a.AttributeType));

            foreach (var instance in attributes)
            {
                SuppressMessageInfo info;
                if (!TryDecodeSuppressMessageAttributeData(instance, out info))
                {
                    continue;
                }

                var scope = info.Scope?.ToLower();
                if (info.Target == null && (scope == "module" || scope == null))
                {
                    yield return(info, provider);

                    continue;
                }

                switch (scope)
                {
                case "module":
                    yield return(info, provider);

                    break;

                case "type":
                case "member":
                    if (info.Target == null)
                    {
                        break;
                    }

                    foreach (var result in DocumentationSignatureParser.GetMembersForDocumentationSignature(info.Target, module, _context))
                    {
                        yield return(info, result);
                    }

                    break;

                default:
                    _context.LogWarning($"Invalid scope '{info.Scope}' used in 'UnconditionalSuppressMessageAttribute' on module '{module.Name}' " +
                                        $"with target '{info.Target}'.",
                                        2108, _context.GetAssemblyLocation(module.Assembly));
                    break;
                }
            }
        }
Exemple #4
0
        public void LookForModuleLevelAndGlobalSuppressions(ModuleDefinition module, ICustomAttributeProvider provider)
        {
            var attributes = _context.CustomAttributes.GetCustomAttributes(provider).
                             Where(a => TypeRefHasUnconditionalSuppressions(a.AttributeType));

            foreach (var instance in attributes)
            {
                SuppressMessageInfo info;
                if (!TryDecodeSuppressMessageAttributeData(instance, out info))
                {
                    continue;
                }

                if (info.Target == null && (info.Scope == "module" || info.Scope == null))
                {
                    AddSuppression(info, provider);
                    continue;
                }

                if (info.Target == null || info.Scope == null)
                {
                    continue;
                }

                switch (info.Scope)
                {
                case "type":
                case "member":
                    foreach (var result in DocumentationSignatureParser.GetMembersForDocumentationSignature(info.Target, module))
                    {
                        AddSuppression(info, result);
                    }

                    break;

                default:
                    _context.LogMessage($"Scope `{info.Scope}` used in `UnconditionalSuppressMessage` is currently not supported.");
                    break;
                }
            }
        }