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;
                }
            }
        }
Esempio n. 2
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;
                }
            }
        }