-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide extension methods for path operations
- Loading branch information
Showing
9 changed files
with
116 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Templates.Core.Gen; | ||
|
||
namespace Microsoft.Templates.Core.Extensions | ||
{ | ||
public static class PathExtensions | ||
{ | ||
public static string GetPathRelativeToGenerationParentPath(this string filePath) | ||
{ | ||
var generationParentDirectory = Directory.GetParent(GenContext.Current.GenerationOutputPath).FullName; | ||
return GetRelativePath(filePath, generationParentDirectory); | ||
} | ||
|
||
public static string GetPathRelativeToGenerationPath(this string filePath) | ||
{ | ||
var generationParentDirectory = GenContext.Current.GenerationOutputPath; | ||
return GetRelativePath(filePath, generationParentDirectory); | ||
} | ||
|
||
public static string GetPathRelativeToDestinationParentPath(this string filePath) | ||
{ | ||
var generationParentDirectory = Directory.GetParent(GenContext.Current.DestinationPath).FullName; | ||
return GetRelativePath(filePath, generationParentDirectory); | ||
} | ||
|
||
public static string GetDestinationPath(this string filePath) | ||
{ | ||
var parentGenerationOutputPath = Directory.GetParent(GenContext.Current.GenerationOutputPath).FullName; | ||
var parentDestinationPath = Directory.GetParent(GenContext.Current.DestinationPath).FullName; | ||
|
||
return filePath.Replace(parentGenerationOutputPath, parentDestinationPath); | ||
} | ||
|
||
public static string GetGenerationPath(this string filePath) | ||
{ | ||
var parentGenerationOutputPath = Directory.GetParent(GenContext.Current.GenerationOutputPath).FullName; | ||
var parentDestinationPath = Directory.GetParent(GenContext.Current.DestinationPath).FullName; | ||
|
||
return filePath.Replace(parentDestinationPath, parentGenerationOutputPath); | ||
} | ||
|
||
private static string GetRelativePath(this string filePath, string folderName) | ||
{ | ||
if (filePath.Contains(folderName)) | ||
{ | ||
return filePath.Replace(folderName + Path.DirectorySeparatorChar, string.Empty); | ||
} | ||
|
||
// TODO: Should this throw an exception? | ||
return filePath; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.