Skip to content

Commit 9f6a7be

Browse files
committed
Add relative method in FilePath
1 parent 85089bc commit 9f6a7be

6 files changed

Lines changed: 27 additions & 12 deletions

File tree

src/Antelcat.AutoGen.SourceGenerators/Antelcat.AutoGen.SourceGenerators.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Feast.CodeAnalysis" Version="0.1.8">
15+
<PackageReference Include="Feast.CodeAnalysis" Version="0.1.11">
1616
<PrivateAssets>all</PrivateAssets>
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
</PackageReference>
19+
<PackageReference Include="Feast.CodeAnalysis.Literal" Version="0.1.4" />
1920
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
2021
<PrivateAssets>all</PrivateAssets>
2122
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/Antelcat.AutoGen.SourceGenerators/FilePath.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public readonly ref struct FilePath
3535
/// <summary>
3636
/// <see cref="System.IO.Path.GetPathRoot"/>
3737
/// </summary>
38-
public string PathRoot => Path.GetPathRoot(path);
38+
public string? PathRoot => Path.GetPathRoot(path);
3939

4040
/// <summary>
4141
/// <see cref="System.IO.Path.GetExtension"/>
@@ -60,27 +60,33 @@ public readonly ref struct FilePath
6060

6161
public static FilePath operator *(FilePath path, int times)
6262
{
63-
var result = path.ToString();
63+
var result = path.path;
6464
while (times-- > 0)
6565
{
66-
result += path.ToString();
66+
result += path.path;
6767
}
6868

6969
return result;
7070
}
7171

7272
public static FilePath operator <<(FilePath path, int times)
7373
{
74-
var result = path.ToString();
74+
var result = path.path;
7575
while (times-- > 0)
7676
{
7777
result = Path.GetDirectoryName(result);
7878
}
7979

8080
return result;
8181
}
82-
83-
public static implicit operator FilePath(string path) => new(path);
82+
83+
#if NET || NETSTANDARD2_1
84+
public static FilePath operator >>(FilePath from, FilePath to) => global::System.IO.Path.GetRelativePath(from, to);
85+
86+
public static FilePath operator <<(FilePath to, FilePath from) => global::System.IO.Path.GetRelativePath(from, to);
87+
#endif
88+
89+
public static implicit operator FilePath(string path) => new(path);
8490
public static implicit operator FilePath(string[] paths) => Path.Combine(paths);
85-
public static implicit operator string(FilePath path) => path.ToString();
91+
public static implicit operator string(FilePath path) => path.path;
8692
}

src/Antelcat.AutoGen.Tests/SampleSourceGeneratorTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using System.Diagnostics;
5+
using System.IO;
56
using System.Linq;
67
using System.Text.Json;
78
using Antelcat.AutoGen.SourceGenerators.Generators;

src/Antelcat.AutoGen.Tests/StringExtensionGeneratorTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,11 @@ x is
9191
.First();
9292
var props = cs.GetProperties();
9393
}
94+
95+
[Test]
96+
public void TestPath()
97+
{
98+
var relative1 = (FilePath)@"d:\A\B\C" >> @"d:\A\D";
99+
var relative2 = (FilePath)@"d:\A\B\C" << @"d:\A\D";
100+
}
94101
}

src/Antelcat.AutoGen/Antelcat.AutoGen.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<IsPackable>true</IsPackable>
88
<LangVersion>preview</LangVersion>
99

10-
<Version>1.2.6</Version>
11-
<FileVersion>1.2.4</FileVersion>
12-
<AssemblyVersion>1.2.4</AssemblyVersion>
10+
<Version>1.2.7</Version>
11+
<FileVersion>1.2.7</FileVersion>
12+
<AssemblyVersion>1.2.7</AssemblyVersion>
1313

1414
<Authors>Antelcat</Authors>
1515
<Title>Antelcat.AutoGen</Title>

0 commit comments

Comments
 (0)