Skip to content

Commit d83da30

Browse files
authored
Use global:: prefix (#84)
1 parent c9014f3 commit d83da30

File tree

7 files changed

+176
-3
lines changed

7 files changed

+176
-3
lines changed

src/ProxyInterfaceSourceGenerator/FileGenerators/ProxyClassesGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private string GeneratePublicProperties(ClassSymbol targetClassSymbol, ProxyData
134134

135135
var instance = !property.IsStatic ?
136136
"_Instance" :
137-
$"{targetClassSymbol.Symbol}";
137+
$"{targetClassSymbol.Symbol.ToFullyQualifiedDisplayString()}";
138138

139139
var propertyName = property.GetSanitizedName();
140140
var instancePropertyName = $"{instance}.{propertyName}";
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//----------------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//----------------------------------------------------------------------------------------
9+
10+
#nullable enable
11+
using System;
12+
13+
namespace ProxyInterfaceSourceGeneratorTests.Source
14+
{
15+
public partial interface ITimeProvider
16+
{
17+
global::System.TimeProvider _Instance { get; }
18+
19+
global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider System { get; }
20+
21+
global::System.TimeZoneInfo LocalTimeZone { get; }
22+
23+
long TimestampFrequency { get; }
24+
25+
global::System.DateTimeOffset GetUtcNow();
26+
27+
global::System.DateTimeOffset GetLocalNow();
28+
29+
long GetTimestamp();
30+
31+
global::System.TimeSpan GetElapsedTime(long startingTimestamp, long endingTimestamp);
32+
33+
global::System.TimeSpan GetElapsedTime(long startingTimestamp);
34+
35+
global::System.Threading.ITimer CreateTimer(global::System.Threading.TimerCallback callback, object? state, global::System.TimeSpan dueTime, global::System.TimeSpan period);
36+
}
37+
}
38+
#nullable restore

tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonExtendsProxy.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public partial class PersonExtendsProxy : global::ProxyInterfaceSourceGeneratorT
1818

1919
public global::ProxyInterfaceSourceGeneratorTests.Source.PersonExtends _Instance { get; }
2020

21-
public string StaticString { get => ProxyInterfaceSourceGeneratorTests.Source.PersonExtends.StaticString; set => ProxyInterfaceSourceGeneratorTests.Source.PersonExtends.StaticString = value; }
21+
public string StaticString { get => global::ProxyInterfaceSourceGeneratorTests.Source.PersonExtends.StaticString; set => global::ProxyInterfaceSourceGeneratorTests.Source.PersonExtends.StaticString = value; }
2222

2323
public string Name { get => _Instance.Name; set => _Instance.Name = value; }
2424

tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpClientProxy.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public partial class HttpClientProxy : global::ProxyInterfaceSourceGeneratorTest
1818

1919
public new global::System.Net.Http.HttpClient _Instance { get; }
2020
public global::System.Net.Http.HttpMessageInvoker _InstanceHttpMessageInvoker { get; }
21-
public global::System.Net.IWebProxy DefaultProxy { get => System.Net.Http.HttpClient.DefaultProxy; set => System.Net.Http.HttpClient.DefaultProxy = value; }
21+
public global::System.Net.IWebProxy DefaultProxy { get => global::System.Net.Http.HttpClient.DefaultProxy; set => global::System.Net.Http.HttpClient.DefaultProxy = value; }
2222

2323
public global::System.Net.Http.Headers.HttpRequestHeaders DefaultRequestHeaders { get => _Instance.DefaultRequestHeaders; }
2424

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//----------------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//----------------------------------------------------------------------------------------
9+
10+
#nullable enable
11+
using System;
12+
13+
namespace ProxyInterfaceSourceGeneratorTests.Source
14+
{
15+
public partial class TimeProviderProxy : global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider
16+
{
17+
static TimeProviderProxy()
18+
{
19+
Mapster.TypeAdapterConfig<global::System.TimeProvider, global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider>.NewConfig().ConstructUsing(instance98737229 => new global::ProxyInterfaceSourceGeneratorTests.Source.TimeProviderProxy(instance98737229));
20+
Mapster.TypeAdapterConfig<global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider, global::System.TimeProvider>.NewConfig().MapWith(proxy_979750559 => ((global::ProxyInterfaceSourceGeneratorTests.Source.TimeProviderProxy) proxy_979750559)._Instance);
21+
22+
}
23+
24+
25+
public global::System.TimeProvider _Instance { get; }
26+
27+
public global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider System { get => Mapster.TypeAdapter.Adapt<global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider>(global::System.TimeProvider.System); }
28+
29+
public virtual global::System.TimeZoneInfo LocalTimeZone { get => _Instance.LocalTimeZone; }
30+
31+
public virtual long TimestampFrequency { get => _Instance.TimestampFrequency; }
32+
33+
public virtual global::System.DateTimeOffset GetUtcNow()
34+
{
35+
var result__1870298920 = _Instance.GetUtcNow();
36+
return result__1870298920;
37+
}
38+
39+
public global::System.DateTimeOffset GetLocalNow()
40+
{
41+
var result__1410738147 = _Instance.GetLocalNow();
42+
return result__1410738147;
43+
}
44+
45+
public virtual long GetTimestamp()
46+
{
47+
var result__1193196790 = _Instance.GetTimestamp();
48+
return result__1193196790;
49+
}
50+
51+
public global::System.TimeSpan GetElapsedTime(long startingTimestamp, long endingTimestamp)
52+
{
53+
long startingTimestamp_ = startingTimestamp;
54+
long endingTimestamp_ = endingTimestamp;
55+
var result__865310895 = _Instance.GetElapsedTime(startingTimestamp_, endingTimestamp_);
56+
return result__865310895;
57+
}
58+
59+
public global::System.TimeSpan GetElapsedTime(long startingTimestamp)
60+
{
61+
long startingTimestamp_ = startingTimestamp;
62+
var result__865310895 = _Instance.GetElapsedTime(startingTimestamp_);
63+
return result__865310895;
64+
}
65+
66+
public virtual global::System.Threading.ITimer CreateTimer(global::System.Threading.TimerCallback callback, object? state, global::System.TimeSpan dueTime, global::System.TimeSpan period)
67+
{
68+
global::System.Threading.TimerCallback callback_ = callback;
69+
object? state_ = state;
70+
global::System.TimeSpan dueTime_ = dueTime;
71+
global::System.TimeSpan period_ = period;
72+
var result_1335635543 = _Instance.CreateTimer(callback_, state_, dueTime_, period_);
73+
return result_1335635543;
74+
}
75+
76+
77+
public TimeProviderProxy(global::System.TimeProvider instance)
78+
{
79+
_Instance = instance;
80+
81+
}
82+
}
83+
}
84+
#nullable restore

tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,4 +786,49 @@ public Task GenerateFiles_ForClassWithIgnores_Regex()
786786
var results = result.GeneratorDriver.GetRunResult().Results.First().GeneratedSources;
787787
return Verify(results);
788788
}
789+
790+
[Fact]
791+
public void GenerateFiles_ForTimeProvider_Should_GenerateCorrectFiles()
792+
{
793+
// Arrange
794+
var fileNames = new[]
795+
{
796+
"ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider.g.cs",
797+
"System.TimeProviderProxy.g.cs"
798+
};
799+
800+
var path = Path.Combine(_basePath, "Source/ITimeProvider.cs");
801+
var sourceFile = new SourceFile
802+
{
803+
Path = path,
804+
Text = File.ReadAllText(path),
805+
AttributeToAddToInterface = new ExtraAttribute
806+
{
807+
Name = "ProxyInterfaceGenerator.Proxy",
808+
ArgumentList = "typeof(System.TimeProvider)"
809+
}
810+
};
811+
812+
// Act
813+
var result = _sut.Execute([sourceFile]);
814+
815+
// Assert
816+
Assert(result, fileNames);
817+
}
818+
819+
private void Assert(ExecuteResult result, string[] fileNames)
820+
{
821+
result.Valid.Should().BeTrue();
822+
result.Files.Should().HaveCount(fileNames.Length + 1);
823+
824+
foreach (var fileName in fileNames.Select((fileName, index) => new { fileName, index }))
825+
{
826+
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
827+
builder.Path.Should().EndWith(fileName.fileName);
828+
829+
var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}");
830+
if (Write) File.WriteAllText(destinationFilename, builder.Text);
831+
builder.Text.Should().Be(File.ReadAllText(destinationFilename));
832+
}
833+
}
789834
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace ProxyInterfaceSourceGeneratorTests.Source
2+
{
3+
public partial interface ITimeProvider
4+
{
5+
}
6+
}

0 commit comments

Comments
 (0)