src/Misc/EFTools/EntityDesign/VisualStudio/EdmUtils.cs
// <summary>
//     Returns a path for "directory1" relative to "directory2"
// </summary>
Returns a path for "directory1" relative to "directory2"
Returns a path for " directory1 " relative to " directory2 "
internal static string GetRelativePath(DirectoryInfo directory1, DirectoryInfo directory2)
        {
            var d = directory1;
            var root1 = d.Root;
            var root2 = directory2.Root;
            if (!root1.Name.ToUpperInvariant().Equals(root2.Name.ToUpperInvariant()))
            {
                throw new ArgumentException(Resources.ModelObjectItemWizard_CantBeRelative);
            }
            var filePathParts = new LinkedList<DirectoryInfo>();
            var directoryPathParts = new LinkedList<DirectoryInfo>();
            while (d != null
                   && !d.Equals(d.Root))
            {
                filePathParts.AddFirst(new DirectoryInfo(d.Name));
                d = d.Parent;
            }
            d = directory2;
            while (d != null
                   && !d.Equals(d.Root))
            {
                directoryPathParts.AddFirst(new DirectoryInfo(d.Name));
                d = d.Parent;
            }
            while (directoryPathParts.Count > 0
                   && filePathParts.Count > 0)
            {
                var d1 = filePathParts.First.Value;
                var d2 = directoryPathParts.First.Value;
                if (d1.Name.ToUpperInvariant().Equals(d2.Name.ToUpperInvariant()))
                {
                    filePathParts.RemoveFirst();
                    directoryPathParts.RemoveFirst();
                }
                else
                {
                    break;
                }
            }
            var sb = new StringBuilder();
            sb.Append(".\\");
            for (var i = 0; i < directoryPathParts.Count; i++)
            {
                sb.Append("..\\");
            }
            foreach (var di in filePathParts)
            {
                sb.Append(di.Name + "\\");
            }
            return sb.ToString();
        }
internal static string GetRelativePath ( DirectoryInfo directory1 , DirectoryInfo directory2 ) { var d = directory1 ; var root1 = d . Root ; var root2 = directory2 . Root ; if ( ! root1 . Name . ToUpperInvariant ( ) . Equals ( root2 . Name . ToUpperInvariant ( ) ) ) { throw new ArgumentException ( Resources . ModelObjectItemWizard_CantBeRelative ) ; } var filePathParts = new LinkedList < DirectoryInfo > ( ) ; var directoryPathParts = new LinkedList < DirectoryInfo > ( ) ; while ( d != null && ! d . Equals ( d . Root ) ) { filePathParts . AddFirst ( new DirectoryInfo ( d . Name ) ) ; d = d . Parent ; } d = directory2 ; while ( d != null && ! d . Equals ( d . Root ) ) { directoryPathParts . AddFirst ( new DirectoryInfo ( d . Name ) ) ; d = d . Parent ; } while ( directoryPathParts . Count > 0 && filePathParts . Count > 0 ) { var d1 = filePathParts . First . Value ; var d2 = directoryPathParts . First . Value ; if ( d1 . Name . ToUpperInvariant ( ) . Equals ( d2 . Name . ToUpperInvariant ( ) ) ) { filePathParts . RemoveFirst ( ) ; directoryPathParts . RemoveFirst ( ) ; } else { break ; } } var sb = new StringBuilder ( ) ; sb . Append ( " \\ " ) ; for ( var i = 0 ; i < directoryPathParts . Count ; i ++ ) { sb . Append ( " \\ " ) ; } foreach ( var di in filePathParts ) { sb . Append ( di . Name + " \\ " ) ; } return sb . ToString ( ) ; }
Returns a path for "directory1" relative to "directory2"
Returns a path for " directory1 " relative to " directory2 "
// remove all common directories at the head of the list. // add in a "..\" for each directory part left in the "from" list // add in the directory name for each directory part left in the "to" list
directory1
DirectoryInfo
directory2
DirectoryInfo