public RuleSet?LoadRuleSet(RuleSet parent)
        {
            // Try to load the rule set
            RuleSet?ruleSet = null;

            string?path = _includePath;

            try
            {
                path = GetIncludePath(parent);
                if (path == null)
                {
                    return(null);
                }

                ruleSet = RuleSetProcessor.LoadFromFile(path);
            }
            catch (FileNotFoundException)
            {
                // The compiler uses the same rule set files as FxCop, but doesn't have all of
                // the same logic for resolving included files. For the moment, just ignore any
                // includes we can't resolve.
            }
            catch (Exception e)
            {
                throw new InvalidRuleSetException(string.Format(CodeAnalysisResources.InvalidRuleSetInclude, path, e.Message));
            }

            return(ruleSet);
        }
Beispiel #2
0
        /// <summary>
        /// Get the paths to all files contributing rules to the ruleset from the specified file.
        /// See also: <seealso cref="LoadEffectiveRuleSetFromFile(string)" />.
        /// </summary>
        /// <returns>
        /// The full paths to included files, or an empty array if there were errors.
        /// </returns>
        public static ImmutableArray <string> GetEffectiveIncludesFromFile(string filePath)
        {
            var ruleSet = RuleSetProcessor.LoadFromFile(filePath);

            if (ruleSet != null)
            {
                return(ruleSet.GetEffectiveIncludes());
            }

            return(ImmutableArray <string> .Empty);
        }
Beispiel #3
0
        /// <summary>
        /// Load the ruleset from the specified file. This ruleset will contain
        /// all the rules resolved from the includes specified in the ruleset file
        /// as well. See also: <seealso cref="GetEffectiveIncludesFromFile(string)" />.
        /// </summary>
        /// <returns>
        /// A ruleset that contains resolved rules or null if there were errors.
        /// </returns>
        public static RuleSet LoadEffectiveRuleSetFromFile(string filePath)
        {
            var ruleSet = RuleSetProcessor.LoadFromFile(filePath);

            if (ruleSet != null)
            {
                return(ruleSet.GetEffectiveRuleSet(new HashSet <string>()));
            }

            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Gets the RuleSet associated with this ruleset include
        /// </summary>
        /// <param name="parent">The parent of this ruleset include</param>
        public RuleSet LoadRuleSet(RuleSet parent)
        {
            // Try to load the rule set
            RuleSet ruleSet = null;

            string path = _includePath;

            try
            {
                path    = GetIncludePath(parent);
                ruleSet = RuleSetProcessor.LoadFromFile(path);
            }
            catch (Exception e)
            {
                throw new InvalidRuleSetException(string.Format(CodeAnalysisResources.InvalidRuleSetInclude, path, e.Message));
            }

            return(ruleSet);
        }
Beispiel #5
0
        /// <summary>
        /// Gets the RuleSet associated with this ruleset include
        /// </summary>
        /// <param name="parent">The parent of this ruleset include</param>
        public RuleSet LoadRuleSet(RuleSet parent)
        {
            // Try to load the rule set
            RuleSet   ruleSet = null;
            Exception ex      = null;

            string path = _includePath;

            try
            {
                path    = GetIncludePath(parent);
                ruleSet = RuleSetProcessor.LoadFromFile(path);
            }
            catch (ArgumentException e)
            { ex = e; }
            catch (FileNotFoundException)
            {
                // The compiler uses the same rule set files as FxCop, but doesn't have all of
                // the same logic for resolving included files. For the moment, just ignore any
                // includes we can't resolve.
            }
            catch (IOException e)
            { ex = e; }
            catch (UriFormatException e)
            { ex = e; }
            catch (SecurityException e)
            { ex = e; }
            catch (UnauthorizedAccessException e)
            { ex = e; }
            catch (XmlException e)
            { ex = e; }
            catch (InvalidRuleSetException e)
            { ex = e; }

            if (ex != null)
            {
                throw new InvalidRuleSetException(string.Format(CodeAnalysisResources.InvalidRuleSetInclude, path, ex.Message));
            }

            return(ruleSet);
        }
Beispiel #6
0
        /// <summary>
        /// Gets the RuleSet associated with this ruleset include
        /// </summary>
        /// <param name="parent">The parent of this ruleset include</param>
        public RuleSet LoadRuleSet(RuleSet parent)
        {
            // Try to load the rule set
            RuleSet   ruleSet = null;
            Exception ex      = null;

            string path = includePath;

            try
            {
                path    = GetIncludePath(parent);
                ruleSet = RuleSetProcessor.LoadFromFile(path);
            }
            catch (ArgumentException e)
            { ex = e; }
            catch (FileNotFoundException e)
            { ex = e; }
            catch (IOException e)
            { ex = e; }
            catch (UriFormatException e)
            { ex = e; }
            catch (SecurityException e)
            { ex = e; }
            catch (UnauthorizedAccessException e)
            { ex = e; }
            catch (XmlException e)
            { ex = e; }
            catch (InvalidRuleSetException e)
            { ex = e; }

            if (ex != null)
            {
                throw new InvalidRuleSetException(string.Format(CodeAnalysisResources.InvalidRuleSetInclude, path, ex.Message));
            }

            return(ruleSet);
        }