CalculateRelativePath() 공개 정적인 메소드

Compute the path of toFullPath, relative to fromFullPath.
public static CalculateRelativePath ( string fromFullPath, string toFullPath ) : string
fromFullPath string Path with which to make relative to
toFullPath string Absolute path
리턴 string
        /// <summary>
        /// Return a non-nested include from source to target
        /// </summary>
        /// <param name="source">Required</param>
        /// <param name="target">Required</param>
        /// <returns><see cref="RuleSetInclude"/> or null if not found</returns>
        public static RuleSetInclude FindInclude(RuleSet source, RuleSet target)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            string relativeTargetFilePath = PathHelper.CalculateRelativePath(source.FilePath, target.FilePath);

            var matchingRuleSetIncludes = source.RuleSetIncludes.Where(i =>
                                                                       StringComparer.OrdinalIgnoreCase.Equals(i.FilePath, relativeTargetFilePath) ||
                                                                       StringComparer.OrdinalIgnoreCase.Equals(i.FilePath, target.FilePath))
                                          .ToList();

            if (matchingRuleSetIncludes.Count == 0)
            {
                return(null);
            }
            else if (matchingRuleSetIncludes.Count == 1)
            {
                return(matchingRuleSetIncludes[0]);
            }
            else
            {
                // Only caller use this result decide whether or not we are bound so finding more than one hit should still
                // return the element to say we are bound.
                Debug.Fail("Not expecting to find multiple RuleSetInclude matching the filter");
                return(matchingRuleSetIncludes[0]);
            }
        }
        /// <summary>
        /// Return a non-nested include from source to target
        /// </summary>
        /// <param name="source">Required</param>
        /// <param name="target">Required</param>
        /// <returns><see cref="RuleSetInclude"/> or null if not found</returns>
        public static RuleSetInclude FindInclude(RuleSet source, RuleSet target)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            string relativeTargetFilePath = PathHelper.CalculateRelativePath(source.FilePath, target.FilePath);

            return(source.RuleSetIncludes.SingleOrDefault(i =>
                                                          StringComparer.OrdinalIgnoreCase.Equals(i.FilePath, relativeTargetFilePath) ||
                                                          StringComparer.OrdinalIgnoreCase.Equals(i.FilePath, target.FilePath)));
        }
        /// <summary>
        /// Updates the <paramref name="ruleSet"/> by deleting all the previously included rule sets
        /// that were in the same folder as <paramref name="solutionRuleSetPath"/> and then includes
        /// the rule set specified by <paramref name="solutionRuleSetPath"/>.
        /// </summary>
        /// <remarks>
        /// The update is in-memory to the <paramref name="ruleSet"/> and we rely on the fact that we
        /// previously generated the 'solutionRuleSet' to the same folder as the updated <paramref name="solutionRuleSetPath"/></remarks>
        /// <param name="ruleSet">Existing project level rule set</param>
        /// <param name="solutionRuleSetPath">Full path of solution level rule set (one that was generated during bind)</param>
        public static void UpdateExistingProjectRuleSet(RuleSet ruleSet, string solutionRuleSetPath)
        {
            Debug.Assert(ruleSet != null);
            Debug.Assert(!string.IsNullOrWhiteSpace(solutionRuleSetPath));

            string projectRuleSetPath = ruleSet.FilePath;

            Debug.Assert(!string.IsNullOrWhiteSpace(projectRuleSetPath));

            // Remove all solution level inclusions
            string solutionRuleSetRoot = PathHelper.ForceDirectoryEnding(Path.GetDirectoryName(solutionRuleSetPath));

            RuleSetHelper.RemoveAllIncludesUnderRoot(ruleSet, solutionRuleSetRoot);

            // Add correct inclusion
            string expectedIncludePath = PathHelper.CalculateRelativePath(projectRuleSetPath, solutionRuleSetPath);

            ruleSet.RuleSetIncludes.Add(new RuleSetInclude(expectedIncludePath, RuleAction.Default));
        }