예제 #1
0
        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);
        }
예제 #2
0
파일: RuleSet.cs 프로젝트: sshyran/roslyn
        /// <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);
        }
예제 #3
0
파일: RuleSet.cs 프로젝트: sshyran/roslyn
        /// <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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }