/// <summary>
 /// Creates a suppressed record based on a diagnostic record and the rule suppression
 /// </summary>
 /// <param name="record"></param>
 /// <param name="Suppression"></param>
 public SuppressedRecord(DiagnosticRecord record, RuleSuppression suppression)
 {
     Suppression = suppression;
     if (record != null)
     {
         RuleName          = record.RuleName;
         Message           = record.Message;
         Extent            = record.Extent;
         Severity          = record.Severity;
         ScriptName        = record.ScriptName;
         RuleSuppressionID = record.RuleSuppressionID;
     }
 }
        /// <summary>
        /// Given a list of attribute asts, return a list of rule suppression
        /// with startoffset at start and endoffset at end
        /// </summary>
        /// <param name="attrAsts"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public static List <RuleSuppression> GetSuppressions(IEnumerable <AttributeAst> attrAsts, int start, int end, Ast scopeAst)
        {
            List <RuleSuppression> result = new List <RuleSuppression>();

            if (attrAsts == null || scopeAst == null)
            {
                return(result);
            }

            IEnumerable <AttributeAst> suppressionAttribute = attrAsts.Where(
                item => item.TypeName.GetReflectionType() == typeof(System.Diagnostics.CodeAnalysis.SuppressMessageAttribute));

            foreach (var attributeAst in suppressionAttribute)
            {
                RuleSuppression ruleSupp = new RuleSuppression(attributeAst, start, end);

                // If there is no error and scope is not null
                if (String.IsNullOrWhiteSpace(ruleSupp.Error) && !String.IsNullOrWhiteSpace(ruleSupp.Scope))
                {
                    if (String.IsNullOrWhiteSpace(ruleSupp.Target))
                    {
                        ruleSupp.Target = "*";
                    }

                    // regex for wild card *
                    Regex             reg        = new Regex(String.Format("^{0}$", Regex.Escape(ruleSupp.Target).Replace(@"\*", ".*")), RegexOptions.IgnoreCase);
                    IEnumerable <Ast> targetAsts = null;

                    switch (ruleSupp.Scope.ToLower())
                    {
                    case "function":
                        targetAsts = scopeAst.FindAll(item => item is FunctionDefinitionAst && reg.IsMatch((item as FunctionDefinitionAst).Name), true);
                        goto default;

                    case "class":
                        targetAsts = scopeAst.FindAll(item => item is TypeDefinitionAst && reg.IsMatch((item as TypeDefinitionAst).Name), true);
                        goto default;

                    default:
                        break;
                    }

                    if (targetAsts != null)
                    {
                        if (targetAsts.Count() == 0)
                        {
                            ruleSupp.Error = String.Format(CultureInfo.CurrentCulture, Strings.RuleSuppressionErrorFormat, ruleSupp.StartAttributeLine,
                                                           System.IO.Path.GetFileName(scopeAst.Extent.File), String.Format(Strings.TargetCannotBeFoundError, ruleSupp.Target, ruleSupp.Scope));
                            result.Add(ruleSupp);
                            continue;
                        }

                        foreach (Ast targetAst in targetAsts)
                        {
                            result.Add(new RuleSuppression(ruleSupp.RuleName, ruleSupp.RuleSuppressionID, targetAst.Extent.StartOffset,
                                                           targetAst.Extent.EndOffset, attributeAst.Extent.StartLineNumber, ruleSupp.Justification));
                        }
                    }
                }
                else
                {
                    // this may add rule suppression that contains error but we will check for this in the engine to throw out error
                    result.Add(ruleSupp);
                }
            }

            return(result);
        }