Skip to content

Commit

Permalink
Use global:: prefix (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH authored Jan 10, 2025
1 parent c9014f3 commit d83da30
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private string GeneratePublicProperties(ClassSymbol targetClassSymbol, ProxyData

var instance = !property.IsStatic ?
"_Instance" :
$"{targetClassSymbol.Symbol}";
$"{targetClassSymbol.Symbol.ToFullyQualifiedDisplayString()}";

var propertyName = property.GetSanitizedName();
var instancePropertyName = $"{instance}.{propertyName}";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//----------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//----------------------------------------------------------------------------------------

#nullable enable
using System;

namespace ProxyInterfaceSourceGeneratorTests.Source
{
public partial interface ITimeProvider
{
global::System.TimeProvider _Instance { get; }

global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider System { get; }

global::System.TimeZoneInfo LocalTimeZone { get; }

long TimestampFrequency { get; }

global::System.DateTimeOffset GetUtcNow();

global::System.DateTimeOffset GetLocalNow();

long GetTimestamp();

global::System.TimeSpan GetElapsedTime(long startingTimestamp, long endingTimestamp);

global::System.TimeSpan GetElapsedTime(long startingTimestamp);

global::System.Threading.ITimer CreateTimer(global::System.Threading.TimerCallback callback, object? state, global::System.TimeSpan dueTime, global::System.TimeSpan period);
}
}
#nullable restore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class PersonExtendsProxy : global::ProxyInterfaceSourceGeneratorT

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class HttpClientProxy : global::ProxyInterfaceSourceGeneratorTest

public new global::System.Net.Http.HttpClient _Instance { get; }
public global::System.Net.Http.HttpMessageInvoker _InstanceHttpMessageInvoker { get; }
public global::System.Net.IWebProxy DefaultProxy { get => System.Net.Http.HttpClient.DefaultProxy; set => System.Net.Http.HttpClient.DefaultProxy = value; }
public global::System.Net.IWebProxy DefaultProxy { get => global::System.Net.Http.HttpClient.DefaultProxy; set => global::System.Net.Http.HttpClient.DefaultProxy = value; }

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//----------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//----------------------------------------------------------------------------------------

#nullable enable
using System;

namespace ProxyInterfaceSourceGeneratorTests.Source
{
public partial class TimeProviderProxy : global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider
{
static TimeProviderProxy()
{
Mapster.TypeAdapterConfig<global::System.TimeProvider, global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider>.NewConfig().ConstructUsing(instance98737229 => new global::ProxyInterfaceSourceGeneratorTests.Source.TimeProviderProxy(instance98737229));
Mapster.TypeAdapterConfig<global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider, global::System.TimeProvider>.NewConfig().MapWith(proxy_979750559 => ((global::ProxyInterfaceSourceGeneratorTests.Source.TimeProviderProxy) proxy_979750559)._Instance);

}


public global::System.TimeProvider _Instance { get; }

public global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider System { get => Mapster.TypeAdapter.Adapt<global::ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider>(global::System.TimeProvider.System); }

public virtual global::System.TimeZoneInfo LocalTimeZone { get => _Instance.LocalTimeZone; }

public virtual long TimestampFrequency { get => _Instance.TimestampFrequency; }

public virtual global::System.DateTimeOffset GetUtcNow()
{
var result__1870298920 = _Instance.GetUtcNow();
return result__1870298920;
}

public global::System.DateTimeOffset GetLocalNow()
{
var result__1410738147 = _Instance.GetLocalNow();
return result__1410738147;
}

public virtual long GetTimestamp()
{
var result__1193196790 = _Instance.GetTimestamp();
return result__1193196790;
}

public global::System.TimeSpan GetElapsedTime(long startingTimestamp, long endingTimestamp)
{
long startingTimestamp_ = startingTimestamp;
long endingTimestamp_ = endingTimestamp;
var result__865310895 = _Instance.GetElapsedTime(startingTimestamp_, endingTimestamp_);
return result__865310895;
}

public global::System.TimeSpan GetElapsedTime(long startingTimestamp)
{
long startingTimestamp_ = startingTimestamp;
var result__865310895 = _Instance.GetElapsedTime(startingTimestamp_);
return result__865310895;
}

public virtual global::System.Threading.ITimer CreateTimer(global::System.Threading.TimerCallback callback, object? state, global::System.TimeSpan dueTime, global::System.TimeSpan period)
{
global::System.Threading.TimerCallback callback_ = callback;
object? state_ = state;
global::System.TimeSpan dueTime_ = dueTime;
global::System.TimeSpan period_ = period;
var result_1335635543 = _Instance.CreateTimer(callback_, state_, dueTime_, period_);
return result_1335635543;
}


public TimeProviderProxy(global::System.TimeProvider instance)
{
_Instance = instance;

}
}
}
#nullable restore
Original file line number Diff line number Diff line change
Expand Up @@ -786,4 +786,49 @@ public Task GenerateFiles_ForClassWithIgnores_Regex()
var results = result.GeneratorDriver.GetRunResult().Results.First().GeneratedSources;
return Verify(results);
}

[Fact]
public void GenerateFiles_ForTimeProvider_Should_GenerateCorrectFiles()
{
// Arrange
var fileNames = new[]
{
"ProxyInterfaceSourceGeneratorTests.Source.ITimeProvider.g.cs",
"System.TimeProviderProxy.g.cs"
};

var path = Path.Combine(_basePath, "Source/ITimeProvider.cs");
var sourceFile = new SourceFile
{
Path = path,
Text = File.ReadAllText(path),
AttributeToAddToInterface = new ExtraAttribute
{
Name = "ProxyInterfaceGenerator.Proxy",
ArgumentList = "typeof(System.TimeProvider)"
}
};

// Act
var result = _sut.Execute([sourceFile]);

// Assert
Assert(result, fileNames);
}

private void Assert(ExecuteResult result, string[] fileNames)
{
result.Valid.Should().BeTrue();
result.Files.Should().HaveCount(fileNames.Length + 1);

foreach (var fileName in fileNames.Select((fileName, index) => new { fileName, index }))
{
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
builder.Path.Should().EndWith(fileName.fileName);

var destinationFilename = Path.Combine(_basePath, $"Destination/{fileName.fileName}");
if (Write) File.WriteAllText(destinationFilename, builder.Text);
builder.Text.Should().Be(File.ReadAllText(destinationFilename));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ProxyInterfaceSourceGeneratorTests.Source
{
public partial interface ITimeProvider
{
}
}

0 comments on commit d83da30

Please sign in to comment.