diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..a271784 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "csharpier": { + "version": "0.28.2", + "commands": [ + "dotnet-csharpier" + ] + } + } +} \ No newline at end of file diff --git a/src-examples/ProxyInterfaceConsumer/Address.cs b/src-examples/ProxyInterfaceConsumer/Address.cs index cc6333a..f03a7c0 100644 --- a/src-examples/ProxyInterfaceConsumer/Address.cs +++ b/src-examples/ProxyInterfaceConsumer/Address.cs @@ -10,6 +10,7 @@ namespace ProxyInterfaceConsumer [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] public event EventHandler MyEvent = null!; public int Weird { get; set; } + public int Weird2() { return 0; diff --git a/src-examples/ProxyInterfaceConsumer/Http/IHttpClient.cs b/src-examples/ProxyInterfaceConsumer/Http/IHttpClient.cs index cbd0a8a..5ef47f5 100644 --- a/src-examples/ProxyInterfaceConsumer/Http/IHttpClient.cs +++ b/src-examples/ProxyInterfaceConsumer/Http/IHttpClient.cs @@ -3,11 +3,7 @@ using System.Net.Http; namespace ProxyInterfaceConsumer.Http; [ProxyInterfaceGenerator.Proxy(typeof(HttpClient), true)] -public partial interface IHttpClient : IHttpMessageInvoker -{ -} +public partial interface IHttpClient : IHttpMessageInvoker { } [ProxyInterfaceGenerator.Proxy(typeof(HttpMessageInvoker))] -public partial interface IHttpMessageInvoker -{ -} \ No newline at end of file +public partial interface IHttpMessageInvoker { } diff --git a/src-examples/ProxyInterfaceConsumer/Http/IHttpClientExtensions.cs b/src-examples/ProxyInterfaceConsumer/Http/IHttpClientExtensions.cs index 0ad8080..fb061b2 100644 --- a/src-examples/ProxyInterfaceConsumer/Http/IHttpClientExtensions.cs +++ b/src-examples/ProxyInterfaceConsumer/Http/IHttpClientExtensions.cs @@ -13,96 +13,212 @@ namespace ProxyInterfaceConsumer.Http; public static class IHttpClientExtensions { #region PostAsJsonAsync - public static Task PostAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) + public static Task PostAsJsonAsync( + this IHttpClient client, + [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, + TValue value, + JsonSerializerOptions? options = null, + CancellationToken cancellationToken = default + ) { return client._Instance.PostAsJsonAsync(requestUri, value, options, cancellationToken); } - public static Task PostAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) + public static Task PostAsJsonAsync( + this IHttpClient client, + Uri? requestUri, + TValue value, + JsonSerializerOptions? options = null, + CancellationToken cancellationToken = default + ) { return client._Instance.PostAsJsonAsync(requestUri, value, options, cancellationToken); } - public static Task PostAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, CancellationToken cancellationToken) + public static Task PostAsJsonAsync( + this IHttpClient client, + [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, + TValue value, + CancellationToken cancellationToken + ) { - return client._Instance.PostAsJsonAsync(requestUri, value, options: null, cancellationToken); + return client._Instance.PostAsJsonAsync( + requestUri, + value, + options: null, + cancellationToken + ); } - public static Task PostAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, CancellationToken cancellationToken) + public static Task PostAsJsonAsync( + this IHttpClient client, + Uri? requestUri, + TValue value, + CancellationToken cancellationToken + ) { - return client._Instance.PostAsJsonAsync(requestUri, value, options: null, cancellationToken); + return client._Instance.PostAsJsonAsync( + requestUri, + value, + options: null, + cancellationToken + ); } - public static Task PostAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + public static Task PostAsJsonAsync( + this IHttpClient client, + [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, + TValue value, + JsonTypeInfo jsonTypeInfo, + CancellationToken cancellationToken = default + ) { return client._Instance.PostAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken); } - public static Task PostAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + public static Task PostAsJsonAsync( + this IHttpClient client, + Uri? requestUri, + TValue value, + JsonTypeInfo jsonTypeInfo, + CancellationToken cancellationToken = default + ) { return client._Instance.PostAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken); } #endregion #region GetFromJsonAsync - public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, Type type, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync( + this IHttpClient client, + [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, + Type type, + JsonSerializerOptions? options, + CancellationToken cancellationToken = default + ) { return client._Instance.GetFromJsonAsync(requestUri, type, options, cancellationToken); } - public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, Type type, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync( + this IHttpClient client, + Uri? requestUri, + Type type, + JsonSerializerOptions? options, + CancellationToken cancellationToken = default + ) { return client._Instance.GetFromJsonAsync(requestUri, type, options, cancellationToken); } - public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync( + this IHttpClient client, + [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, + JsonSerializerOptions? options, + CancellationToken cancellationToken = default + ) { return client._Instance.GetFromJsonAsync(requestUri, options, cancellationToken); } - public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync( + this IHttpClient client, + Uri? requestUri, + JsonSerializerOptions? options, + CancellationToken cancellationToken = default + ) { return client._Instance.GetFromJsonAsync(requestUri, options, cancellationToken); } - public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, Type type, JsonSerializerContext context, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync( + this IHttpClient client, + [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, + Type type, + JsonSerializerContext context, + CancellationToken cancellationToken = default + ) { return client._Instance.GetFromJsonAsync(requestUri, type, context, cancellationToken); } - public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, Type type, JsonSerializerContext context, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync( + this IHttpClient client, + Uri? requestUri, + Type type, + JsonSerializerContext context, + CancellationToken cancellationToken = default + ) { return client._Instance.GetFromJsonAsync(requestUri, type, context, cancellationToken); } - public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync( + this IHttpClient client, + [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, + JsonTypeInfo jsonTypeInfo, + CancellationToken cancellationToken = default + ) { return client._Instance.GetFromJsonAsync(requestUri, jsonTypeInfo, cancellationToken); } - public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync( + this IHttpClient client, + Uri? requestUri, + JsonTypeInfo jsonTypeInfo, + CancellationToken cancellationToken = default + ) { return client._Instance.GetFromJsonAsync(requestUri, jsonTypeInfo, cancellationToken); } - public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, Type type, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync( + this IHttpClient client, + [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, + Type type, + CancellationToken cancellationToken = default + ) { - return client._Instance.GetFromJsonAsync(requestUri, type, options: null, cancellationToken); + return client._Instance.GetFromJsonAsync( + requestUri, + type, + options: null, + cancellationToken + ); } - public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, Type type, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync( + this IHttpClient client, + Uri? requestUri, + Type type, + CancellationToken cancellationToken = default + ) { - return client._Instance.GetFromJsonAsync(requestUri, type, options: null, cancellationToken); + return client._Instance.GetFromJsonAsync( + requestUri, + type, + options: null, + cancellationToken + ); } - public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync( + this IHttpClient client, + [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, + CancellationToken cancellationToken = default + ) { return client._Instance.GetFromJsonAsync(requestUri, cancellationToken); } - public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync( + this IHttpClient client, + Uri? requestUri, + CancellationToken cancellationToken = default + ) { return client._Instance.GetFromJsonAsync(requestUri, cancellationToken); } #endregion -} \ No newline at end of file +} diff --git a/src-examples/ProxyInterfaceConsumer/IAddress.cs b/src-examples/ProxyInterfaceConsumer/IAddress.cs index ba32668..6e890dc 100644 --- a/src-examples/ProxyInterfaceConsumer/IAddress.cs +++ b/src-examples/ProxyInterfaceConsumer/IAddress.cs @@ -2,7 +2,7 @@ using ProxyInterfaceGenerator; namespace ProxyInterfaceConsumer { - [Proxy(typeof(Address), false, ProxyClassAccessibility.Public, new []{"Weird"})] + [Proxy(typeof(Address), false, ProxyClassAccessibility.Public, new[] { "Weird" })] public partial interface IAddress { public void Weird() @@ -10,4 +10,4 @@ namespace ProxyInterfaceConsumer _Instance.Weird2(); } } -} \ No newline at end of file +} diff --git a/src-examples/ProxyInterfaceConsumer/IGeneratorExecutionContext.cs b/src-examples/ProxyInterfaceConsumer/IGeneratorExecutionContext.cs index 06adf82..30a57d1 100644 --- a/src-examples/ProxyInterfaceConsumer/IGeneratorExecutionContext.cs +++ b/src-examples/ProxyInterfaceConsumer/IGeneratorExecutionContext.cs @@ -1,7 +1,5 @@ namespace ProxyInterfaceConsumer { // [ProxyInterfaceGenerator.Proxy(typeof(Microsoft.CodeAnalysis.GeneratorExecutionContext))] - public partial interface IGeneratorExecutionContext - { - } -} \ No newline at end of file + public partial interface IGeneratorExecutionContext { } +} diff --git a/src-examples/ProxyInterfaceConsumer/IMyInterface.cs b/src-examples/ProxyInterfaceConsumer/IMyInterface.cs index d616e32..4e2f0ab 100644 --- a/src-examples/ProxyInterfaceConsumer/IMyInterface.cs +++ b/src-examples/ProxyInterfaceConsumer/IMyInterface.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceConsumer { - public interface IMyInterface - { - } -} \ No newline at end of file + public interface IMyInterface { } +} diff --git a/src-examples/ProxyInterfaceConsumer/IPerson.cs b/src-examples/ProxyInterfaceConsumer/IPerson.cs index 156aaed..5313ac0 100644 --- a/src-examples/ProxyInterfaceConsumer/IPerson.cs +++ b/src-examples/ProxyInterfaceConsumer/IPerson.cs @@ -3,7 +3,5 @@ using ProxyInterfaceGenerator; namespace ProxyInterfaceConsumer { [Proxy(typeof(ProxyInterfaceConsumer.Person), ProxyClassAccessibility.Internal)] - public partial interface IPerson - { - } -} \ No newline at end of file + public partial interface IPerson { } +} diff --git a/src-examples/ProxyInterfaceConsumer/IPersonT.cs b/src-examples/ProxyInterfaceConsumer/IPersonT.cs index 3153816..a354f07 100644 --- a/src-examples/ProxyInterfaceConsumer/IPersonT.cs +++ b/src-examples/ProxyInterfaceConsumer/IPersonT.cs @@ -2,6 +2,5 @@ namespace ProxyInterfaceConsumer { [ProxyInterfaceGenerator.Proxy(typeof(ProxyInterfaceConsumer.PersonT<>))] public partial interface IPersonT // where T : struct - { - } -} \ No newline at end of file + { } +} diff --git a/src-examples/ProxyInterfaceConsumer/IPersonTT.cs b/src-examples/ProxyInterfaceConsumer/IPersonTT.cs index 16df005..b0c2203 100644 --- a/src-examples/ProxyInterfaceConsumer/IPersonTT.cs +++ b/src-examples/ProxyInterfaceConsumer/IPersonTT.cs @@ -1,9 +1,7 @@ namespace ProxyInterfaceConsumer { [ProxyInterfaceGenerator.Proxy(typeof(ProxyInterfaceConsumer.PersonTT<,>))] - public partial interface IPersonTT + public partial interface IPersonTT where T1 : struct - where T2 : class, new() - { - } -} \ No newline at end of file + where T2 : class, new() { } +} diff --git a/src-examples/ProxyInterfaceConsumer/Person.cs b/src-examples/ProxyInterfaceConsumer/Person.cs index f1d4b25..26ac387 100644 --- a/src-examples/ProxyInterfaceConsumer/Person.cs +++ b/src-examples/ProxyInterfaceConsumer/Person.cs @@ -10,28 +10,30 @@ namespace ProxyInterfaceConsumer public int Id { get; } [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public object @object { get; set; }= null!; + public object @object { get; set; } = null!; public long? NullableLong { get; } [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public string Name { get; set; }= null!; + public string Name { get; set; } = null!; public string? StringNullable { get; set; } [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public Address Address { get; set; }= null!; + public Address Address { get; set; } = null!; [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public List
AddressesList { get; set; }= null!; + public List
AddressesList { get; set; } = null!; - public Dictionary AddressesDict { get; set; } = new Dictionary(); - public Dictionary AddressesDict2 { get; set; } = new Dictionary(); + public Dictionary AddressesDict { get; set; } = + new Dictionary(); + public Dictionary AddressesDict2 { get; set; } = + new Dictionary(); public E E { get; set; } [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public IMyInterface MyInterface { get; set; }= null!; + public IMyInterface MyInterface { get; set; } = null!; public bool TMethod(int x, T1 t1, T2 t2) where T1 : struct @@ -55,9 +57,7 @@ namespace ProxyInterfaceConsumer return $"Hello {name} !"; } - public void AddWithParams(params string[] values) - { - } + public void AddWithParams(params string[] values) { } public Address AddAddress(Address a) { @@ -66,9 +66,7 @@ namespace ProxyInterfaceConsumer return a; } - public void AddAddresses(params Address[] addresses) - { - } + public void AddAddresses(params Address[] addresses) { } public void In_Out_Ref1(in int a, out int b, ref int c) { @@ -83,9 +81,7 @@ namespace ProxyInterfaceConsumer // return 404; //} - public void Void() - { - } + public void Void() { } public Task Method1Async() { diff --git a/src-examples/ProxyInterfaceConsumer/PersonT.cs b/src-examples/ProxyInterfaceConsumer/PersonT.cs index 4e46bf7..d0acddb 100644 --- a/src-examples/ProxyInterfaceConsumer/PersonT.cs +++ b/src-examples/ProxyInterfaceConsumer/PersonT.cs @@ -1,6 +1,7 @@ namespace ProxyInterfaceConsumer { - public class PersonT where T : struct + public class PersonT + where T : struct { public T TVal { get; set; } @@ -14,4 +15,4 @@ namespace ProxyInterfaceConsumer return new PersonT(); } } -} \ No newline at end of file +} diff --git a/src-examples/ProxyInterfaceConsumer/PersonTT.cs b/src-examples/ProxyInterfaceConsumer/PersonTT.cs index b474a58..f3c5d98 100644 --- a/src-examples/ProxyInterfaceConsumer/PersonTT.cs +++ b/src-examples/ProxyInterfaceConsumer/PersonTT.cs @@ -8,8 +8,6 @@ namespace ProxyInterfaceConsumer public T2 TVal2 { get; set; } - public void Call(int x, T1 t1, T2 t2) - { - } + public void Call(int x, T1 t1, T2 t2) { } } -} \ No newline at end of file +} diff --git a/src-examples/ProxyInterfaceConsumer/Program.cs b/src-examples/ProxyInterfaceConsumer/Program.cs index 79a5759..75fed0c 100644 --- a/src-examples/ProxyInterfaceConsumer/Program.cs +++ b/src-examples/ProxyInterfaceConsumer/Program.cs @@ -11,10 +11,7 @@ namespace ProxyInterfaceConsumer; public class Program { - private static JsonSerializerOptions JsonSerializerOptions = new () - { - WriteIndented = true - }; + private static JsonSerializerOptions JsonSerializerOptions = new() { WriteIndented = true }; public static async Task Main() { @@ -24,7 +21,10 @@ public class Program var result = await ph.GetAsync("https://www.google.nl"); var todo = await ph.GetFromJsonAsync("https://jsonplaceholder.typicode.com/todos/1"); - var postResult = await h.PostAsJsonAsync("https://jsonplaceholder.typicode.com/todos", new Todo { Id = 123 }); + var postResult = await h.PostAsJsonAsync( + "https://jsonplaceholder.typicode.com/todos", + new Todo { Id = 123 } + ); var t = new TestProxy(new Test()); @@ -41,9 +41,7 @@ public class Program var ap = new AddressProxy(new Address { HouseNumber = 42 }); ap.HouseNumber = -1; - ap.MyEvent += delegate (object x, EventArgs a) - { - }; + ap.MyEvent += delegate(object x, EventArgs a) { }; IPerson p = new PersonProxy(new Person()); p.Name = "test"; @@ -93,11 +91,7 @@ public sealed class Clazz } [ProxyInterfaceGenerator.Proxy(typeof(Test))] -public partial interface ITest -{ -} +public partial interface ITest { } [ProxyInterfaceGenerator.Proxy(typeof(Clazz))] -public partial interface IClazz -{ -} +public partial interface IClazz { } diff --git a/src-examples/ProxyInterfaceConsumerForAkka/Interfaces/IAddressUid.cs b/src-examples/ProxyInterfaceConsumerForAkka/Interfaces/IAddressUid.cs index 3b9edd4..9c98633 100644 --- a/src-examples/ProxyInterfaceConsumerForAkka/Interfaces/IAddressUid.cs +++ b/src-examples/ProxyInterfaceConsumerForAkka/Interfaces/IAddressUid.cs @@ -4,6 +4,4 @@ using Akka.Remote; [ProxyInterfaceGenerator.Proxy(typeof(AddressUid))] // ReSharper disable once CheckNamespace -public partial interface IAddressUid -{ -} \ No newline at end of file +public partial interface IAddressUid { } diff --git a/src-examples/ProxyInterfaceConsumerForAkka/Interfaces/ILocalActorRefProvider.cs b/src-examples/ProxyInterfaceConsumerForAkka/Interfaces/ILocalActorRefProvider.cs index e56f853..29596c7 100644 --- a/src-examples/ProxyInterfaceConsumerForAkka/Interfaces/ILocalActorRefProvider.cs +++ b/src-examples/ProxyInterfaceConsumerForAkka/Interfaces/ILocalActorRefProvider.cs @@ -3,7 +3,5 @@ using Akka.Actor; namespace ProxyInterfaceConsumerForAkka.Interfaces { [ProxyInterfaceGenerator.Proxy(typeof(LocalActorRefProvider))] - public partial interface ILocalActorRefProvider - { - } -} \ No newline at end of file + public partial interface ILocalActorRefProvider { } +} diff --git a/src-examples/ProxyInterfaceConsumerForPnP/Implementations/ClientContextProxy.cs b/src-examples/ProxyInterfaceConsumerForPnP/Implementations/ClientContextProxy.cs index f960559..1fcc9a9 100644 --- a/src-examples/ProxyInterfaceConsumerForPnP/Implementations/ClientContextProxy.cs +++ b/src-examples/ProxyInterfaceConsumerForPnP/Implementations/ClientContextProxy.cs @@ -11,9 +11,15 @@ namespace ProxyInterfaceConsumerForPnP.Interfaces; [SuppressMessage("ReSharper", "InconsistentNaming")] public partial class ClientContextProxy { - public Task ExecuteQueryRetryAsync(Interfaces.IClientRuntimeContext clientContext, int retryCount = 10, string? userAgent = null) + public Task ExecuteQueryRetryAsync( + Interfaces.IClientRuntimeContext clientContext, + int retryCount = 10, + string? userAgent = null + ) { - ClientRuntimeContext clientObject_ = Mapster.TypeAdapter.Adapt(clientContext); + ClientRuntimeContext clientObject_ = Mapster.TypeAdapter.Adapt( + clientContext + ); return clientObject_.ExecuteQueryRetryAsync(retryCount, userAgent); } @@ -25,17 +31,24 @@ public partial class ClientContextProxy _Instance.Load(clientObject_, retrievals_); } - public void Load(Interfaces.IClientObject clientObject, params Expression>[] retrievals) + public void Load( + Interfaces.IClientObject clientObject, + params Expression>[] retrievals + ) where TSource : Interfaces.IClientObject where TTarget : ClientObject { TTarget clientObject_ = Mapster.TypeAdapter.Adapt(clientObject); - Expression>[] retrievals_ = retrievals.Select(MapExpression).ToArray(); + Expression>[] retrievals_ = retrievals + .Select(MapExpression) + .ToArray(); _Instance.Load(clientObject_, retrievals_); } - private static Expression> MapExpression(Expression> expression) + private static Expression> MapExpression( + Expression> expression + ) where TSource : Interfaces.IClientObject where TTarget : ClientObject { @@ -45,20 +58,28 @@ public partial class ClientContextProxy switch (expression.Body) { case MemberExpression memberExpression: - memberAccessExpression = Expression.PropertyOrField(parameterExpression, memberExpression.Member.Name); + memberAccessExpression = Expression.PropertyOrField( + parameterExpression, + memberExpression.Member.Name + ); break; case UnaryExpression unaryExpression: var expressionOperand = (MemberExpression)unaryExpression.Operand; - memberAccessExpression = Expression.PropertyOrField(parameterExpression, expressionOperand.Member.Name); + memberAccessExpression = Expression.PropertyOrField( + parameterExpression, + expressionOperand.Member.Name + ); memberAccessExpression = Expression.Convert(memberAccessExpression, typeof(object)); break; default: throw new NotSupportedException(); - } - return Expression.Lambda>(memberAccessExpression, parameterExpression); + return Expression.Lambda>( + memberAccessExpression, + parameterExpression + ); } -} \ No newline at end of file +} diff --git a/src-examples/ProxyInterfaceConsumerForPnP/Implementations/ClientRuntimeContextExtensions.cs b/src-examples/ProxyInterfaceConsumerForPnP/Implementations/ClientRuntimeContextExtensions.cs index 49b0536..03bb7f3 100644 --- a/src-examples/ProxyInterfaceConsumerForPnP/Implementations/ClientRuntimeContextExtensions.cs +++ b/src-examples/ProxyInterfaceConsumerForPnP/Implementations/ClientRuntimeContextExtensions.cs @@ -6,9 +6,15 @@ namespace ProxyInterfaceConsumerForPnP.Implementations; public static class ClientRuntimeContextExtensions { - public static Task ExecuteQueryRetryAsync(this IClientRuntimeContext clientContext, int retryCount = 10, string? userAgent = null) + public static Task ExecuteQueryRetryAsync( + this IClientRuntimeContext clientContext, + int retryCount = 10, + string? userAgent = null + ) { - ClientRuntimeContext clientObject_ = Mapster.TypeAdapter.Adapt(clientContext); + ClientRuntimeContext clientObject_ = Mapster.TypeAdapter.Adapt( + clientContext + ); return clientObject_.ExecuteQueryRetryAsync(retryCount, userAgent); } -} \ No newline at end of file +} diff --git a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IClientContext.cs b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IClientContext.cs index 4fbe561..f1f6030 100644 --- a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IClientContext.cs +++ b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IClientContext.cs @@ -7,8 +7,11 @@ namespace ProxyInterfaceConsumerForPnP.Interfaces [ProxyInterfaceGenerator.Proxy(typeof(ClientContext))] public partial interface IClientContext : IClientRuntimeContext { - void Load(IClientObject clientObject, params Expression>[] retrievals) + void Load( + IClientObject clientObject, + params Expression>[] retrievals + ) where TSource : IClientObject where TTarget : ClientObject; } -} \ No newline at end of file +} diff --git a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IClientObject.cs b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IClientObject.cs index 66c266d..c01e167 100644 --- a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IClientObject.cs +++ b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IClientObject.cs @@ -1,7 +1,5 @@ namespace ProxyInterfaceConsumerForPnP.Interfaces { [ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.ClientObject))] - public partial interface IClientObject - { - } -} \ No newline at end of file + public partial interface IClientObject { } +} diff --git a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IClientRuntimeContext.cs b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IClientRuntimeContext.cs index d94cb3d..b30a5c6 100644 --- a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IClientRuntimeContext.cs +++ b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IClientRuntimeContext.cs @@ -1,8 +1,5 @@ namespace ProxyInterfaceConsumerForPnP.Interfaces { [ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.ClientRuntimeContext))] - public partial interface IClientRuntimeContext - { - - } -} \ No newline at end of file + public partial interface IClientRuntimeContext { } +} diff --git a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IListCollection.cs b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IListCollection.cs index 11f2db1..0daf778 100644 --- a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IListCollection.cs +++ b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IListCollection.cs @@ -7,4 +7,4 @@ // public partial interface IProxyListCollection: IClientObject, IEnumerable, IQueryable // { // } -//} \ No newline at end of file +//} diff --git a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/ISecurableObject.cs b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/ISecurableObject.cs index 37e90a7..ebe042e 100644 --- a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/ISecurableObject.cs +++ b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/ISecurableObject.cs @@ -5,4 +5,4 @@ namespace ProxyInterfaceConsumerForPnP.Interfaces { // public virtual void X(); } -} \ No newline at end of file +} diff --git a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IUser.cs b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IUser.cs index ba4eb8b..c6e29db 100644 --- a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IUser.cs +++ b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IUser.cs @@ -1,7 +1,5 @@ namespace ProxyInterfaceConsumerForPnP.Interfaces { [ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.User))] - public partial interface IUser - { - } -} \ No newline at end of file + public partial interface IUser { } +} diff --git a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IWeb.cs b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IWeb.cs index d3f013b..4cd6c6f 100644 --- a/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IWeb.cs +++ b/src-examples/ProxyInterfaceConsumerForPnP/Interfaces/IWeb.cs @@ -1,7 +1,5 @@ namespace ProxyInterfaceConsumerForPnP.Interfaces { [ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.Web))] - public partial interface IWeb: ISecurableObject - { - } -} \ No newline at end of file + public partial interface IWeb : ISecurableObject { } +} diff --git a/src-examples/ProxyInterfaceConsumerForPnP/Program.cs b/src-examples/ProxyInterfaceConsumerForPnP/Program.cs index b5ee24a..9d212b5 100644 --- a/src-examples/ProxyInterfaceConsumerForPnP/Program.cs +++ b/src-examples/ProxyInterfaceConsumerForPnP/Program.cs @@ -18,9 +18,12 @@ public class Program "15b347bf-90a2-4c16-aa76-5a3263476b59", "Test.pfx", Environment.GetEnvironmentVariable("Test.pfx_PWD"), - "s7gb6.onmicrosoft.com"); + "s7gb6.onmicrosoft.com" + ); - using var clientContext = await authManager.GetContextAsync("https://s7gb6.sharepoint.com/sites/Test"); + using var clientContext = await authManager.GetContextAsync( + "https://s7gb6.sharepoint.com/sites/Test" + ); clientContext.Load(clientContext.Web, p => p.Title); await clientContext.ExecuteQueryRetryAsync(); @@ -28,7 +31,12 @@ public class Program IClientContext cp = new ClientContextProxy(clientContext); - cp.Load(cp.Web, w => w.Lists, w => w.Language, w => w.Author); + cp.Load( + cp.Web, + w => w.Lists, + w => w.Language, + w => w.Author + ); await cp.ExecuteQueryRetryAsync(); @@ -55,4 +63,4 @@ public class Program Console.WriteLine("Error Message: " + ex.Message); } } -} \ No newline at end of file +} diff --git a/src-examples/ProxyInterfaceConsumerViaNuGet/Address.cs b/src-examples/ProxyInterfaceConsumerViaNuGet/Address.cs index c4db154..3646971 100644 --- a/src-examples/ProxyInterfaceConsumerViaNuGet/Address.cs +++ b/src-examples/ProxyInterfaceConsumerViaNuGet/Address.cs @@ -4,4 +4,4 @@ { public int HouseNumber { get; set; } } -} \ No newline at end of file +} diff --git a/src-examples/ProxyInterfaceConsumerViaNuGet/IAddress.cs b/src-examples/ProxyInterfaceConsumerViaNuGet/IAddress.cs index 514c7fd..64d9436 100644 --- a/src-examples/ProxyInterfaceConsumerViaNuGet/IAddress.cs +++ b/src-examples/ProxyInterfaceConsumerViaNuGet/IAddress.cs @@ -1,7 +1,5 @@ namespace ProxyInterfaceConsumer { [ProxyInterfaceGenerator.Proxy(typeof(ProxyInterfaceConsumer.Address))] - public partial interface IAddress - { - } -} \ No newline at end of file + public partial interface IAddress { } +} diff --git a/src-examples/ProxyInterfaceConsumerViaNuGet/IMyInterface.cs b/src-examples/ProxyInterfaceConsumerViaNuGet/IMyInterface.cs index d616e32..4e2f0ab 100644 --- a/src-examples/ProxyInterfaceConsumerViaNuGet/IMyInterface.cs +++ b/src-examples/ProxyInterfaceConsumerViaNuGet/IMyInterface.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceConsumer { - public interface IMyInterface - { - } -} \ No newline at end of file + public interface IMyInterface { } +} diff --git a/src-examples/ProxyInterfaceConsumerViaNuGet/IPerson.cs b/src-examples/ProxyInterfaceConsumerViaNuGet/IPerson.cs index f6f5b19..1ad7063 100644 --- a/src-examples/ProxyInterfaceConsumerViaNuGet/IPerson.cs +++ b/src-examples/ProxyInterfaceConsumerViaNuGet/IPerson.cs @@ -3,7 +3,5 @@ using ProxyInterfaceGenerator; namespace ProxyInterfaceConsumer { [Proxy(typeof(Person), ProxyClassAccessibility.Internal)] - public partial interface IPerson - { - } -} \ No newline at end of file + public partial interface IPerson { } +} diff --git a/src-examples/ProxyInterfaceConsumerViaNuGet/Person.cs b/src-examples/ProxyInterfaceConsumerViaNuGet/Person.cs index 68f67d4..a7c0a50 100644 --- a/src-examples/ProxyInterfaceConsumerViaNuGet/Person.cs +++ b/src-examples/ProxyInterfaceConsumerViaNuGet/Person.cs @@ -10,37 +10,37 @@ namespace ProxyInterfaceConsumer public int Id { get; } [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public object @object { get; set; }= null!; + public object @object { get; set; } = null!; public long? NullableLong { get; } [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public string Name { get; set; }= null!; + public string Name { get; set; } = null!; public string? StringNullable { get; set; } [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public Address Address { get; set; }= null!; + public Address Address { get; set; } = null!; [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public List
AddressesLIst { get; set; }= null!; + public List
AddressesLIst { get; set; } = null!; - public Dictionary AddressesDict { get; set; } = new Dictionary(); - public Dictionary AddressesDict2 { get; set; } = new Dictionary(); + public Dictionary AddressesDict { get; set; } = + new Dictionary(); + public Dictionary AddressesDict2 { get; set; } = + new Dictionary(); public E E { get; set; } [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public IMyInterface MyInterface { get; set; }= null!; + public IMyInterface MyInterface { get; set; } = null!; public string Add(string s, string @string) { return s + @string; } - public void AddWithParams(params string[] values) - { - } + public void AddWithParams(params string[] values) { } public Address AddAddress(Address a) { @@ -49,9 +49,7 @@ namespace ProxyInterfaceConsumer return a; } - public void AddAddresses(params Address[] addresses) - { - } + public void AddAddresses(params Address[] addresses) { } public void In_Out_Ref1(in int a, out int b, ref int c) { @@ -64,9 +62,7 @@ namespace ProxyInterfaceConsumer return 404; } - public void Void() - { - } + public void Void() { } public Task Method1Async() { diff --git a/src-examples/ProxyInterfaceConsumerViaNuGet/Program.cs b/src-examples/ProxyInterfaceConsumerViaNuGet/Program.cs index 798085d..c424747 100644 --- a/src-examples/ProxyInterfaceConsumerViaNuGet/Program.cs +++ b/src-examples/ProxyInterfaceConsumerViaNuGet/Program.cs @@ -5,10 +5,7 @@ namespace ProxyInterfaceConsumer { class Program { - private static JsonSerializerOptions JsonSerializerOptions = new () - { - WriteIndented = true - }; + private static JsonSerializerOptions JsonSerializerOptions = new() { WriteIndented = true }; static void Main(string[] args) { @@ -24,4 +21,4 @@ namespace ProxyInterfaceConsumer Console.WriteLine(JsonSerializer.Serialize(p, JsonSerializerOptions)); } } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Builders/MethodParameterBuilder.cs b/src/Speckle.ProxyGenerator/Builders/MethodParameterBuilder.cs index f3f48e6..6555034 100644 --- a/src/Speckle.ProxyGenerator/Builders/MethodParameterBuilder.cs +++ b/src/Speckle.ProxyGenerator/Builders/MethodParameterBuilder.cs @@ -16,10 +16,10 @@ internal static class MethodParameterBuilder stringBuilder.Append(parameterSymbol.GetRefKindPrefix()); // "" or "out " stringBuilder.AppendFormat("{0} ", type); // string or another type } - + stringBuilder.Append(parameterSymbol.GetSanitizedName()); // "s" or "i" or ... stringBuilder.Append(parameterSymbol.GetDefaultValue()); // "" or the value return stringBuilder.ToString(); } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Enums/TypeEnum.cs b/src/Speckle.ProxyGenerator/Enums/TypeEnum.cs index 7875c68..1238eb7 100644 --- a/src/Speckle.ProxyGenerator/Enums/TypeEnum.cs +++ b/src/Speckle.ProxyGenerator/Enums/TypeEnum.cs @@ -7,4 +7,4 @@ internal enum TypeEnum Interface, Complex -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Extensions/MethodSymbolExtensions.cs b/src/Speckle.ProxyGenerator/Extensions/MethodSymbolExtensions.cs index e8b7f61..b0ce945 100644 --- a/src/Speckle.ProxyGenerator/Extensions/MethodSymbolExtensions.cs +++ b/src/Speckle.ProxyGenerator/Extensions/MethodSymbolExtensions.cs @@ -5,8 +5,10 @@ namespace Speckle.ProxyGenerator.Extensions; internal static class MethodSymbolExtensions { public static string GetMethodNameWithOptionalTypeParameters(this IMethodSymbol method) => - !method.IsGenericMethod ? method.Name : $"{method.Name}<{string.Join(", ", method.TypeParameters.Select(tp => tp.Name))}>"; + !method.IsGenericMethod + ? method.Name + : $"{method.Name}<{string.Join(", ", method.TypeParameters.Select(tp => tp.Name))}>"; //public static string GetWhereStatement(this IMethodSymbol method) => // !method.IsGenericMethod ? string.Empty : string.Join("", method.TypeParameters.Select(tp => tp.GetWhereConstraints())); -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Extensions/NamedTypeSymbolExtensions.cs b/src/Speckle.ProxyGenerator/Extensions/NamedTypeSymbolExtensions.cs index ac5a2cf..ac1c9b3 100644 --- a/src/Speckle.ProxyGenerator/Extensions/NamedTypeSymbolExtensions.cs +++ b/src/Speckle.ProxyGenerator/Extensions/NamedTypeSymbolExtensions.cs @@ -41,22 +41,34 @@ internal static class NamedTypeSymbolExtensions /// public static string ResolveProxyClassName(this INamedTypeSymbol namedTypeSymbol) { - return !namedTypeSymbol.IsGenericType ? - $"{namedTypeSymbol.Name}Proxy" : - $"{namedTypeSymbol.Name}Proxy<{string.Join(", ", namedTypeSymbol.TypeArguments.Select(ta => ta.Name))}>"; + return !namedTypeSymbol.IsGenericType + ? $"{namedTypeSymbol.Name}Proxy" + : $"{namedTypeSymbol.Name}Proxy<{string.Join(", ", namedTypeSymbol.TypeArguments.Select(ta => ta.Name))}>"; } - public static List ResolveImplementedInterfaces(this INamedTypeSymbol symbol, bool proxyBaseClasses) + public static List ResolveImplementedInterfaces( + this INamedTypeSymbol symbol, + bool proxyBaseClasses + ) { // Members implemented by us or base classes should go here. - var publicMembers = symbol.GetMembers().Where(m => m.DeclaredAccessibility == Accessibility.Public).ToList(); + var publicMembers = symbol + .GetMembers() + .Where(m => m.DeclaredAccessibility == Accessibility.Public) + .ToList(); // Direct interfaces, recursive interfaces or base class interfaces should go here. var interfaces = new List(symbol.Interfaces); var baseType = symbol.BaseType; - while (proxyBaseClasses && baseType != null && baseType.SpecialType != SpecialType.System_Object) + while ( + proxyBaseClasses + && baseType != null + && baseType.SpecialType != SpecialType.System_Object + ) { - publicMembers.AddRange(baseType.GetMembers().Where(m => m.DeclaredAccessibility == Accessibility.Public)); + publicMembers.AddRange( + baseType.GetMembers().Where(m => m.DeclaredAccessibility == Accessibility.Public) + ); interfaces.AddRange(baseType.Interfaces); baseType = baseType.BaseType; } @@ -66,7 +78,10 @@ internal static class NamedTypeSymbolExtensions foreach (var @interface in interfaces) { var isRealized = true; - var allMembers = @interface.AllInterfaces.Aggregate(@interface.GetMembers(), (xs, x) => xs.AddRange(x.GetMembers())); + var allMembers = @interface.AllInterfaces.Aggregate( + @interface.GetMembers(), + (xs, x) => xs.AddRange(x.GetMembers()) + ); foreach (var member in allMembers) { var implementation = symbol.FindImplementationForInterfaceMember(member); @@ -85,4 +100,4 @@ internal static class NamedTypeSymbolExtensions return realizedInterfaces; } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Extensions/ParameterSymbolExtensions.cs b/src/Speckle.ProxyGenerator/Extensions/ParameterSymbolExtensions.cs index 279d45c..c3027b6 100644 --- a/src/Speckle.ProxyGenerator/Extensions/ParameterSymbolExtensions.cs +++ b/src/Speckle.ProxyGenerator/Extensions/ParameterSymbolExtensions.cs @@ -24,7 +24,8 @@ internal static class ParameterSymbolExtensions }; } - public static string GetParamsPrefix(this IParameterSymbol ps) => ps.IsParams ? "params " : string.Empty; + public static string GetParamsPrefix(this IParameterSymbol ps) => + ps.IsParams ? "params " : string.Empty; public static string GetDefaultValue(this IParameterSymbol ps) { @@ -44,7 +45,8 @@ internal static class ParameterSymbolExtensions else { defaultValue = ps.Type.IsReferenceType - ? ParameterValueNull : // The parameter is a ReferenceType, so use "null". + ? ParameterValueNull + : // The parameter is a ReferenceType, so use "null". $"default({ps.Type})"; // The parameter is not a ReferenceType, so use "default(T)". } } @@ -57,4 +59,4 @@ internal static class ParameterSymbolExtensions } public static TypeEnum GetTypeEnum(this IParameterSymbol p) => p.Type.GetTypeEnum(); -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Extensions/PropertySymbolExtensions.cs b/src/Speckle.ProxyGenerator/Extensions/PropertySymbolExtensions.cs index de5e1cf..2ba5cec 100644 --- a/src/Speckle.ProxyGenerator/Extensions/PropertySymbolExtensions.cs +++ b/src/Speckle.ProxyGenerator/Extensions/PropertySymbolExtensions.cs @@ -8,7 +8,10 @@ internal static class PropertySymbolExtensions { public static TypeEnum GetTypeEnum(this IPropertySymbol p) => p.Type.GetTypeEnum(); - public static (string PropertyType, string? PropertyName, string GetSet)? ToPropertyDetails(this IPropertySymbol property, string? overrideType = null) + public static (string PropertyType, string? PropertyName, string GetSet)? ToPropertyDetails( + this IPropertySymbol property, + string? overrideType = null + ) { var getIsPublic = property.GetMethod.IsPublic(); var setIsPublic = property.SetMethod.IsPublic(); @@ -21,9 +24,13 @@ internal static class PropertySymbolExtensions var get = getIsPublic ? "get; " : string.Empty; var set = setIsPublic ? "set; " : string.Empty; - var type = !string.IsNullOrEmpty(overrideType) ? overrideType - : BaseGenerator.FixType(property.Type.ToFullyQualifiedDisplayString(), property.NullableAnnotation); + var type = !string.IsNullOrEmpty(overrideType) + ? overrideType + : BaseGenerator.FixType( + property.Type.ToFullyQualifiedDisplayString(), + property.NullableAnnotation + ); return (type!, property.GetSanitizedName(), $"{{ {get}{set}}}"); } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Extensions/StringExtensions.cs b/src/Speckle.ProxyGenerator/Extensions/StringExtensions.cs index 5967435..1690302 100644 --- a/src/Speckle.ProxyGenerator/Extensions/StringExtensions.cs +++ b/src/Speckle.ProxyGenerator/Extensions/StringExtensions.cs @@ -38,4 +38,4 @@ internal static class StringExtensions { return fullTypeName.Split('.').LastOrDefault() ?? fullTypeName; } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Extensions/SymbolExtensions.cs b/src/Speckle.ProxyGenerator/Extensions/SymbolExtensions.cs index a9ffbf2..099a01e 100644 --- a/src/Speckle.ProxyGenerator/Extensions/SymbolExtensions.cs +++ b/src/Speckle.ProxyGenerator/Extensions/SymbolExtensions.cs @@ -17,7 +17,13 @@ internal static class SymbolExtensions { return symbol .GetAttributes() - .Where(a => a.AttributeClass.IsPublic() && !ExcludedAttributes.Contains(a.AttributeClass?.ToString(), StringComparer.OrdinalIgnoreCase)) + .Where(a => + a.AttributeClass.IsPublic() + && !ExcludedAttributes.Contains( + a.AttributeClass?.ToString(), + StringComparer.OrdinalIgnoreCase + ) + ) .Select(a => $"[{a}]") .ToArray(); } @@ -53,7 +59,10 @@ internal static class SymbolExtensions sb.Insert(0, '.'); } - sb.Insert(0, s.OriginalDefinition.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat)); + sb.Insert( + 0, + s.OriginalDefinition.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat) + ); s = s.ContainingSymbol; } @@ -64,11 +73,12 @@ internal static class SymbolExtensions symbol.IsKeywordOrReserved() ? $"@{symbol.Name}" : symbol.Name; public static bool IsKeywordOrReserved(this ISymbol symbol) => - SyntaxFacts.GetKeywordKind(symbol.Name) != SyntaxKind.None || SyntaxFacts.GetContextualKeywordKind(symbol.Name) != SyntaxKind.None; + SyntaxFacts.GetKeywordKind(symbol.Name) != SyntaxKind.None + || SyntaxFacts.GetContextualKeywordKind(symbol.Name) != SyntaxKind.None; public static bool IsPublic(this ISymbol? symbol) => symbol is { DeclaredAccessibility: Accessibility.Public }; private static bool IsRootNamespace(ISymbol symbol) => symbol is INamespaceSymbol { IsGlobalNamespace: true }; -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Extensions/SyntaxNodeExtensions.cs b/src/Speckle.ProxyGenerator/Extensions/SyntaxNodeExtensions.cs index 39b1c20..2f22618 100644 --- a/src/Speckle.ProxyGenerator/Extensions/SyntaxNodeExtensions.cs +++ b/src/Speckle.ProxyGenerator/Extensions/SyntaxNodeExtensions.cs @@ -7,7 +7,11 @@ namespace Speckle.ProxyGenerator.Extensions; internal static class SyntaxNodeExtensions { // https://stackoverflow.com/questions/20458457/getting-class-fullname-including-namespace-from-roslyn-classdeclarationsyntax - public static bool TryGetParentSyntax(this SyntaxNode? syntaxNode, [NotNullWhen(true)] out T? result) where T : SyntaxNode + public static bool TryGetParentSyntax( + this SyntaxNode? syntaxNode, + [NotNullWhen(true)] out T? result + ) + where T : SyntaxNode { result = null; @@ -57,9 +61,11 @@ internal static class SyntaxNodeExtensions // Keep moving "out" of nested classes etc until we get to a namespace // or until we run out of parents - while (potentialNamespaceParent != null && - potentialNamespaceParent is not NamespaceDeclarationSyntax - && potentialNamespaceParent is not FileScopedNamespaceDeclarationSyntax) + while ( + potentialNamespaceParent != null + && potentialNamespaceParent is not NamespaceDeclarationSyntax + && potentialNamespaceParent is not FileScopedNamespaceDeclarationSyntax + ) { potentialNamespaceParent = potentialNamespaceParent.Parent; } @@ -88,4 +94,4 @@ internal static class SyntaxNodeExtensions // return the final namespace return nameSpace; } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Extensions/TypeSymbolExtensions.cs b/src/Speckle.ProxyGenerator/Extensions/TypeSymbolExtensions.cs index 95616ce..b6a5b72 100644 --- a/src/Speckle.ProxyGenerator/Extensions/TypeSymbolExtensions.cs +++ b/src/Speckle.ProxyGenerator/Extensions/TypeSymbolExtensions.cs @@ -21,8 +21,9 @@ internal static class TypeSymbolExtensions } public static bool IsString(this ITypeSymbol ts) => - ts.ToString().ToLowerInvariant() == "string" || ts.ToString().ToLowerInvariant() == "string?"; + ts.ToString().ToLowerInvariant() == "string" + || ts.ToString().ToLowerInvariant() == "string?"; public static string ToFullyQualifiedDisplayString(this ITypeSymbol property) => property.ToDisplayString(NullableFlowState.None, SymbolDisplayFormat.FullyQualifiedFormat); -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/FileGenerators/BaseGenerator.cs b/src/Speckle.ProxyGenerator/FileGenerators/BaseGenerator.cs index 67e4664..3e1815e 100644 --- a/src/Speckle.ProxyGenerator/FileGenerators/BaseGenerator.cs +++ b/src/Speckle.ProxyGenerator/FileGenerators/BaseGenerator.cs @@ -30,7 +30,10 @@ internal abstract class BaseGenerator return GetReplacedTypeAsString(property.Type, out isReplaced); } - protected bool TryFindProxyDataByTypeName(string type, [NotNullWhen(true)] out ProxyData? proxyData) + protected bool TryFindProxyDataByTypeName( + string type, + [NotNullWhen(true)] out ProxyData? proxyData + ) { proxyData = Context.Candidates.Values.FirstOrDefault(x => x.FullQualifiedTypeName == type); return proxyData != null; @@ -55,16 +58,23 @@ internal abstract class BaseGenerator return string.Concat(list); } - protected string ResolveInterfaceNameWithOptionalTypeConstraints(INamedTypeSymbol namedTypeSymbol, string interfaceName) + protected string ResolveInterfaceNameWithOptionalTypeConstraints( + INamedTypeSymbol namedTypeSymbol, + string interfaceName + ) { if (!namedTypeSymbol.IsGenericType) { return interfaceName; } - var str = new StringBuilder($"{interfaceName}<{string.Join(", ", namedTypeSymbol.TypeArguments.Select(ta => ta.Name))}>"); + var str = new StringBuilder( + $"{interfaceName}<{string.Join(", ", namedTypeSymbol.TypeArguments.Select(ta => ta.Name))}>" + ); - foreach (var typeParameterSymbol in namedTypeSymbol.TypeArguments.OfType()) + foreach ( + var typeParameterSymbol in namedTypeSymbol.TypeArguments.OfType() + ) { if (TryGetWhereConstraints(typeParameterSymbol, false, out var constraint)) { @@ -78,7 +88,11 @@ internal abstract class BaseGenerator /// /// https://www.codeproject.com/Articles/871704/Roslyn-Code-Analysis-in-Easy-Samples-Part-2 /// - public bool TryGetWhereConstraints(ITypeParameterSymbol typeParameterSymbol, bool replaceIt, [NotNullWhen(true)] out ConstraintInfo? constraint) + public bool TryGetWhereConstraints( + ITypeParameterSymbol typeParameterSymbol, + bool replaceIt, + [NotNullWhen(true)] out ConstraintInfo? constraint + ) { var constraints = new List(); if (typeParameterSymbol.HasReferenceTypeConstraint) @@ -91,7 +105,9 @@ internal abstract class BaseGenerator constraints.Add("struct"); } - foreach (var namedTypeSymbol in typeParameterSymbol.ConstraintTypes.OfType()) + foreach ( + var namedTypeSymbol in typeParameterSymbol.ConstraintTypes.OfType() + ) { if (replaceIt) { @@ -120,20 +136,23 @@ internal abstract class BaseGenerator } internal readonly SymbolDisplayFormat NullableDisplayFormat = new SymbolDisplayFormat( - globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included, - typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, - genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, - miscellaneousOptions: - SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers | - SymbolDisplayMiscellaneousOptions.UseSpecialTypes | - SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier); + globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included, + typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, + genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, + miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers + | SymbolDisplayMiscellaneousOptions.UseSpecialTypes + | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier + ); protected string GetReplacedTypeAsString(ITypeSymbol typeSymbol, out bool isReplaced) { isReplaced = false; var typeSymbolAsString = typeSymbol.ToFullyQualifiedDisplayString(); - var nullableTypeSymbolAsString = typeSymbol.ToDisplayString(NullableFlowState.None, NullableDisplayFormat); + var nullableTypeSymbolAsString = typeSymbol.ToDisplayString( + NullableFlowState.None, + NullableDisplayFormat + ); if (TryFindProxyDataByTypeName(typeSymbolAsString, out var existing)) { @@ -171,17 +190,28 @@ internal abstract class BaseGenerator if (!Context.ReplacedTypes.ContainsKey(typeArgumentAsString)) { - Context.ReplacedTypes.Add(typeArgumentAsString, existingTypeArgument.FullInterfaceName); + Context.ReplacedTypes.Add( + typeArgumentAsString, + existingTypeArgument.FullInterfaceName + ); } - propertyTypeAsStringToBeModified = propertyTypeAsStringToBeModified.Replace(typeArgumentAsString, existingTypeArgument.FullInterfaceName); + propertyTypeAsStringToBeModified = propertyTypeAsStringToBeModified.Replace( + typeArgumentAsString, + existingTypeArgument.FullInterfaceName + ); } } return FixType(propertyTypeAsStringToBeModified, typeSymbol.NullableAnnotation); } - protected bool TryGetNamedTypeSymbolByFullName(TypeKind kind, string name, IEnumerable usings, [NotNullWhen(true)] out ClassSymbol? classSymbol) + protected bool TryGetNamedTypeSymbolByFullName( + TypeKind kind, + string name, + IEnumerable usings, + [NotNullWhen(true)] out ClassSymbol? classSymbol + ) { classSymbol = default; const string globalPrefix = "global::"; @@ -195,16 +225,26 @@ internal abstract class BaseGenerator if (symbol is not null && symbol.TypeKind == kind) { - classSymbol = new ClassSymbol(symbol, symbol.GetBaseTypes(), symbol.AllInterfaces.ToList()); + classSymbol = new ClassSymbol( + symbol, + symbol.GetBaseTypes(), + symbol.AllInterfaces.ToList() + ); return true; } foreach (var @using in usings) { - symbol = Context.GeneratorExecutionContext.Compilation.GetTypeByMetadataName($"{@using}.{name}"); + symbol = Context.GeneratorExecutionContext.Compilation.GetTypeByMetadataName( + $"{@using}.{name}" + ); if (symbol is not null && symbol.TypeKind == kind) { - classSymbol = new ClassSymbol(symbol, symbol.GetBaseTypes(), symbol.AllInterfaces.ToList()); + classSymbol = new ClassSymbol( + symbol, + symbol.GetBaseTypes(), + symbol.AllInterfaces.ToList() + ); return true; } } @@ -212,7 +252,10 @@ internal abstract class BaseGenerator return false; } - protected IReadOnlyList GetMethodParameters(ImmutableArray parameterSymbols, bool includeType) + protected IReadOnlyList GetMethodParameters( + ImmutableArray parameterSymbols, + bool includeType + ) { var methodParameters = new List(); foreach (var parameterSymbol in parameterSymbols) @@ -226,7 +269,10 @@ internal abstract class BaseGenerator } else { - type = FixType(parameterSymbol.Type.ToFullyQualifiedDisplayString(), parameterSymbol.NullableAnnotation); + type = FixType( + parameterSymbol.Type.ToFullyQualifiedDisplayString(), + parameterSymbol.NullableAnnotation + ); } } @@ -236,12 +282,17 @@ internal abstract class BaseGenerator return methodParameters; } - protected IReadOnlyList GetExtendsProxyData(ProxyData proxyData, ClassSymbol targetClassSymbol) + protected IReadOnlyList GetExtendsProxyData( + ProxyData proxyData, + ClassSymbol targetClassSymbol + ) { var extendsProxyClasses = new List(); foreach (var baseType in targetClassSymbol.BaseTypes) { - var candidate = Context.Candidates.Values.FirstOrDefault(ci => ci.FullQualifiedTypeName == baseType.ToFullyQualifiedDisplayString()); + var candidate = Context.Candidates.Values.FirstOrDefault(ci => + ci.FullQualifiedTypeName == baseType.ToFullyQualifiedDisplayString() + ); if (candidate is not null) { extendsProxyClasses.Add(candidate); @@ -253,10 +304,13 @@ internal abstract class BaseGenerator internal static string FixType(string type, NullableAnnotation nullableAnnotation) { - if (nullableAnnotation == NullableAnnotation.Annotated && !type.EndsWith("?", StringComparison.Ordinal)) + if ( + nullableAnnotation == NullableAnnotation.Annotated + && !type.EndsWith("?", StringComparison.Ordinal) + ) { return $"{type}?"; } return type; } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/FileGenerators/ExtraFilesGenerator.cs b/src/Speckle.ProxyGenerator/FileGenerators/ExtraFilesGenerator.cs index b94f892..c51121b 100644 --- a/src/Speckle.ProxyGenerator/FileGenerators/ExtraFilesGenerator.cs +++ b/src/Speckle.ProxyGenerator/FileGenerators/ExtraFilesGenerator.cs @@ -8,7 +8,9 @@ internal class ExtraFilesGenerator : IFileGenerator public FileData GenerateFile() { - return new FileData($"{Name}", $@"//---------------------------------------------------------------------------------------- + return new FileData( + $"{Name}", + $@"//---------------------------------------------------------------------------------------- // // This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator. // @@ -61,6 +63,7 @@ namespace ProxyInterfaceGenerator Internal = 1 }} -}}"); +}}" + ); } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/FileGenerators/IFileGenerator.cs b/src/Speckle.ProxyGenerator/FileGenerators/IFileGenerator.cs index cf37fba..0ccabd1 100644 --- a/src/Speckle.ProxyGenerator/FileGenerators/IFileGenerator.cs +++ b/src/Speckle.ProxyGenerator/FileGenerators/IFileGenerator.cs @@ -5,4 +5,4 @@ namespace Speckle.ProxyGenerator.FileGenerators; internal interface IFileGenerator { FileData GenerateFile(); -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/FileGenerators/IFilesGenerator.cs b/src/Speckle.ProxyGenerator/FileGenerators/IFilesGenerator.cs index 3c5988f..1660787 100644 --- a/src/Speckle.ProxyGenerator/FileGenerators/IFilesGenerator.cs +++ b/src/Speckle.ProxyGenerator/FileGenerators/IFilesGenerator.cs @@ -5,4 +5,4 @@ namespace Speckle.ProxyGenerator.FileGenerators; internal interface IFilesGenerator { IEnumerable GenerateFiles(); -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/FileGenerators/PartialInterfacesGenerator.cs b/src/Speckle.ProxyGenerator/FileGenerators/PartialInterfacesGenerator.cs index fa7907b..490be1c 100644 --- a/src/Speckle.ProxyGenerator/FileGenerators/PartialInterfacesGenerator.cs +++ b/src/Speckle.ProxyGenerator/FileGenerators/PartialInterfacesGenerator.cs @@ -11,11 +11,11 @@ namespace Speckle.ProxyGenerator.FileGenerators; internal class PartialInterfacesGenerator : BaseGenerator, IFilesGenerator { - private IReadOnlyCollection _implementedInterfaces = new List(); + private IReadOnlyCollection _implementedInterfaces = + new List(); - public PartialInterfacesGenerator(Context context, bool supportsNullable) : base(context, supportsNullable) - { - } + public PartialInterfacesGenerator(Context context, bool supportsNullable) + : base(context, supportsNullable) { } public IEnumerable GenerateFiles() { @@ -28,21 +28,42 @@ internal class PartialInterfacesGenerator : BaseGenerator, IFilesGenerator } } - private bool TryGenerateFile(InterfaceDeclarationSyntax ci, ProxyData pd, [NotNullWhen(true)] out FileData? fileData) + private bool TryGenerateFile( + InterfaceDeclarationSyntax ci, + ProxyData pd, + [NotNullWhen(true)] out FileData? fileData + ) { fileData = default; - if (!TryGetNamedTypeSymbolByFullName(TypeKind.Interface, ci.Identifier.ToString(), pd.Usings, out var sourceInterfaceSymbol)) + if ( + !TryGetNamedTypeSymbolByFullName( + TypeKind.Interface, + ci.Identifier.ToString(), + pd.Usings, + out var sourceInterfaceSymbol + ) + ) { return false; } - if (!TryGetNamedTypeSymbolByFullName(TypeKind.Class, pd.FullMetadataTypeName, pd.Usings, out var targetClassSymbol)) + if ( + !TryGetNamedTypeSymbolByFullName( + TypeKind.Class, + pd.FullMetadataTypeName, + pd.Usings, + out var targetClassSymbol + ) + ) { return false; } - var interfaceName = ResolveInterfaceNameWithOptionalTypeConstraints(targetClassSymbol.Symbol, pd.ShortInterfaceName); + var interfaceName = ResolveInterfaceNameWithOptionalTypeConstraints( + targetClassSymbol.Symbol, + pd.ShortInterfaceName + ); fileData = new FileData( $"{sourceInterfaceSymbol.Symbol.GetFullMetadataName()}.g.cs", @@ -56,12 +77,19 @@ internal class PartialInterfacesGenerator : BaseGenerator, IFilesGenerator string ns, ClassSymbol classSymbol, string interfaceName, - ProxyData proxyData) + ProxyData proxyData + ) { var extendsProxyClasses = GetExtendsProxyData(proxyData, classSymbol); - _implementedInterfaces = classSymbol.Symbol.ResolveImplementedInterfaces(proxyData.ProxyBaseClasses); - var implementedInterfacesNames = _implementedInterfaces.Select(i => i.ToFullyQualifiedDisplayString()).ToArray(); - var implements = implementedInterfacesNames.Any() ? $" : {string.Join(", ", implementedInterfacesNames)}" : string.Empty; + _implementedInterfaces = classSymbol.Symbol.ResolveImplementedInterfaces( + proxyData.ProxyBaseClasses + ); + var implementedInterfacesNames = _implementedInterfaces + .Select(i => i.ToFullyQualifiedDisplayString()) + .ToArray(); + var implements = implementedInterfacesNames.Any() + ? $" : {string.Join(", ", implementedInterfacesNames)}" + : string.Empty; var @new = extendsProxyClasses.Any() ? "new " : string.Empty; var (namespaceStart, namespaceEnd) = NamespaceBuilder.Build(ns); var events = GenerateEvents(classSymbol, proxyData); @@ -93,12 +121,16 @@ methods} {SupportsNullable.IIf("#nullable restore")}"; } - private Func InterfaceFilter() where T : ISymbol + private Func InterfaceFilter() + where T : ISymbol { var hashSet = new HashSet(); foreach (var @interface in _implementedInterfaces) { - var members = @interface.AllInterfaces.Aggregate(@interface.GetMembers(), (xs, x) => xs.AddRange(x.GetMembers())); + var members = @interface.AllInterfaces.Aggregate( + @interface.GetMembers(), + (xs, x) => xs.AddRange(x.GetMembers()) + ); foreach (var member in members) { hashSet.Add(member.Name); @@ -113,11 +145,19 @@ methods} { var str = new StringBuilder(); - foreach (var property in MemberHelper.GetPublicProperties(targetClassSymbol, proxyData, InterfaceFilter())) + foreach ( + var property in MemberHelper.GetPublicProperties( + targetClassSymbol, + proxyData, + InterfaceFilter() + ) + ) { var type = GetPropertyType(property, out var isReplaced); - var getterSetter = isReplaced ? property.ToPropertyDetails(type) : property.ToPropertyDetails(); + var getterSetter = isReplaced + ? property.ToPropertyDetails(type) + : property.ToPropertyDetails(); if (getterSetter is null) { continue; @@ -136,7 +176,9 @@ methods} str.AppendLine($" {attribute}"); } - str.AppendLine($" {getterSetter.Value.PropertyType} {propertyName} {getterSetter.Value.GetSet}"); + str.AppendLine( + $" {getterSetter.Value.PropertyType} {propertyName} {getterSetter.Value.GetSet}" + ); str.AppendLine(); } return str.ToString(); @@ -145,7 +187,13 @@ methods} private string GenerateMethods(ClassSymbol targetClassSymbol, ProxyData proxyData) { var str = new StringBuilder(); - foreach (var method in MemberHelper.GetPublicMethods(targetClassSymbol, proxyData, InterfaceFilter())) + foreach ( + var method in MemberHelper.GetPublicMethods( + targetClassSymbol, + proxyData, + InterfaceFilter() + ) + ) { var methodParameters = GetMethodParameters(method.Parameters, true); var whereStatement = GetWhereStatementFromMethod(method); @@ -155,7 +203,9 @@ methods} str.AppendLine($" {attribute}"); } - str.AppendLine($" {GetReplacedTypeAsString(method.ReturnType, out _)} {method.GetMethodNameWithOptionalTypeParameters()}({string.Join(", ", methodParameters)}){whereStatement};"); + str.AppendLine( + $" {GetReplacedTypeAsString(method.ReturnType, out _)} {method.GetMethodNameWithOptionalTypeParameters()}({string.Join(", ", methodParameters)}){whereStatement};" + ); str.AppendLine(); } @@ -165,10 +215,19 @@ methods} private string GenerateEvents(ClassSymbol targetClassSymbol, ProxyData proxyData) { var str = new StringBuilder(); - foreach (var @event in MemberHelper.GetPublicEvents(targetClassSymbol, proxyData, InterfaceFilter())) + foreach ( + var @event in MemberHelper.GetPublicEvents( + targetClassSymbol, + proxyData, + InterfaceFilter() + ) + ) { var ps = @event.First().Parameters.First(); - var type = ps.GetTypeEnum() == TypeEnum.Complex ? GetParameterType(ps, out _) : ps.Type.ToString(); + var type = + ps.GetTypeEnum() == TypeEnum.Complex + ? GetParameterType(ps, out _) + : ps.Type.ToString(); foreach (var attribute in ps.GetAttributesAsList()) { @@ -181,4 +240,4 @@ methods} return str.ToString(); } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.AutoMapper.cs b/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.AutoMapper.cs index 138215b..a7708f1 100644 --- a/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.AutoMapper.cs +++ b/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.AutoMapper.cs @@ -19,17 +19,24 @@ internal partial class ProxyClassesGenerator foreach (var replacedType in Context.ReplacedTypes) { TryFindProxyDataByTypeName(replacedType.Key, out var fullTypeName); - var classNameProxy = $"{fullTypeName!.NamespaceDot}{fullTypeName.ShortMetadataName}Proxy"; + var classNameProxy = + $"{fullTypeName!.NamespaceDot}{fullTypeName.ShortMetadataName}Proxy"; - var instance = $"instance{(replacedType.Key + replacedType.Value).GetDeterministicHashCodeAsString()}"; - var proxy = $"proxy{(replacedType.Value + replacedType.Key).GetDeterministicHashCodeAsString()}"; + var instance = + $"instance{(replacedType.Key + replacedType.Value).GetDeterministicHashCodeAsString()}"; + var proxy = + $"proxy{(replacedType.Value + replacedType.Key).GetDeterministicHashCodeAsString()}"; - str.AppendLine($" cfg.CreateMap<{replacedType.Key}, {replacedType.Value}>().ConstructUsing({instance} => new {classNameProxy}({instance}));"); - str.AppendLine($" cfg.CreateMap<{replacedType.Value}, {replacedType.Key}>().ConstructUsing({proxy} => (({classNameProxy}) {proxy})._Instance);"); + str.AppendLine( + $" cfg.CreateMap<{replacedType.Key}, {replacedType.Value}>().ConstructUsing({instance} => new {classNameProxy}({instance}));" + ); + str.AppendLine( + $" cfg.CreateMap<{replacedType.Value}, {replacedType.Key}>().ConstructUsing({proxy} => (({classNameProxy}) {proxy})._Instance);" + ); str.AppendLine(); } str.AppendLine(" }).CreateMapper();"); return str.ToString(); } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.Mapster.cs b/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.Mapster.cs index 4a2a628..c924121 100644 --- a/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.Mapster.cs +++ b/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.Mapster.cs @@ -12,17 +12,24 @@ internal partial class ProxyClassesGenerator foreach (var replacedType in Context.ReplacedTypes) { TryFindProxyDataByTypeName(replacedType.Key, out var fullTypeName); - var classNameProxy = $"global::{fullTypeName!.NamespaceDot}{fullTypeName!.ShortMetadataName}Proxy"; + var classNameProxy = + $"global::{fullTypeName!.NamespaceDot}{fullTypeName!.ShortMetadataName}Proxy"; - var instance = $"instance{(replacedType.Key + replacedType.Value).GetDeterministicHashCodeAsString()}"; - var proxy = $"proxy{(replacedType.Value + replacedType.Key).GetDeterministicHashCodeAsString()}"; + var instance = + $"instance{(replacedType.Key + replacedType.Value).GetDeterministicHashCodeAsString()}"; + var proxy = + $"proxy{(replacedType.Value + replacedType.Key).GetDeterministicHashCodeAsString()}"; - str.AppendLine($" Mapster.TypeAdapterConfig<{replacedType.Key}, {replacedType.Value}>.NewConfig().ConstructUsing({instance} => new {classNameProxy}({instance}));"); - str.AppendLine($" Mapster.TypeAdapterConfig<{replacedType.Value}, {replacedType.Key}>.NewConfig().MapWith({proxy} => (({classNameProxy}) {proxy})._Instance);"); + str.AppendLine( + $" Mapster.TypeAdapterConfig<{replacedType.Key}, {replacedType.Value}>.NewConfig().ConstructUsing({instance} => new {classNameProxy}({instance}));" + ); + str.AppendLine( + $" Mapster.TypeAdapterConfig<{replacedType.Value}, {replacedType.Key}>.NewConfig().MapWith({proxy} => (({classNameProxy}) {proxy})._Instance);" + ); str.AppendLine(); } return str.ToString(); } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.cs b/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.cs index e559580..928d2cc 100644 --- a/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.cs +++ b/src/Speckle.ProxyGenerator/FileGenerators/ProxyClassesGenerator.cs @@ -12,9 +12,8 @@ namespace Speckle.ProxyGenerator.FileGenerators; internal partial class ProxyClassesGenerator : BaseGenerator, IFilesGenerator { - public ProxyClassesGenerator(Context context, bool supportsNullable) : base(context, supportsNullable) - { - } + public ProxyClassesGenerator(Context context, bool supportsNullable) + : base(context, supportsNullable) { } public IEnumerable GenerateFiles() { @@ -27,17 +26,31 @@ internal partial class ProxyClassesGenerator : BaseGenerator, IFilesGenerator } } - [SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1024:Compare symbols correctly", Justification = "")] + [SuppressMessage( + "MicrosoftCodeAnalysisCorrectness", + "RS1024:Compare symbols correctly", + Justification = "" + )] private bool TryGenerateFile(ProxyData pd, [NotNullWhen(true)] out FileData? fileData) { fileData = default; - if (!TryGetNamedTypeSymbolByFullName(TypeKind.Class, pd.FullMetadataTypeName, pd.Usings, out var targetClassSymbol)) + if ( + !TryGetNamedTypeSymbolByFullName( + TypeKind.Class, + pd.FullMetadataTypeName, + pd.Usings, + out var targetClassSymbol + ) + ) { return false; } - var interfaceName = ResolveInterfaceNameWithOptionalTypeConstraints(targetClassSymbol.Symbol, pd.FullInterfaceName); + var interfaceName = ResolveInterfaceNameWithOptionalTypeConstraints( + targetClassSymbol.Symbol, + pd.FullInterfaceName + ); var className = targetClassSymbol.Symbol.ResolveProxyClassName(); var constructorName = $"{targetClassSymbol.Symbol.Name}Proxy"; @@ -45,7 +58,14 @@ internal partial class ProxyClassesGenerator : BaseGenerator, IFilesGenerator fileData = new FileData( $"{targetClassSymbol.Symbol.GetFullMetadataName()}Proxy.g.cs", - CreateProxyClassCode(pd, targetClassSymbol, extendsProxyClasses, interfaceName, className, constructorName) + CreateProxyClassCode( + pd, + targetClassSymbol, + extendsProxyClasses, + interfaceName, + className, + constructorName + ) ); return true; @@ -57,7 +77,8 @@ internal partial class ProxyClassesGenerator : BaseGenerator, IFilesGenerator IReadOnlyList extendsProxyClasses, string interfaceName, string className, - string constructorName) + string constructorName + ) { var firstExtends = extendsProxyClasses.FirstOrDefault(); var extends = string.Empty; @@ -71,8 +92,10 @@ internal partial class ProxyClassesGenerator : BaseGenerator, IFilesGenerator extends = $"global::{firstExtends.NamespaceDot}{firstExtends.ShortMetadataName}Proxy, "; @base = " : base(instance)"; @new = "new "; - instanceBaseDefinition = $"public {firstExtends.FullQualifiedTypeName} _Instance{firstExtends.FullQualifiedTypeName.GetLastPart()} {{ get; }}"; - instanceBaseSetter = $"_Instance{firstExtends.FullQualifiedTypeName.GetLastPart()} = instance;"; + instanceBaseDefinition = + $"public {firstExtends.FullQualifiedTypeName} _Instance{firstExtends.FullQualifiedTypeName.GetLastPart()} {{ get; }}"; + instanceBaseSetter = + $"_Instance{firstExtends.FullQualifiedTypeName.GetLastPart()} = instance;"; } var @abstract = string.Empty; // targetClassSymbol.Symbol.IsAbstract ? "abstract " : string.Empty; @@ -89,7 +112,8 @@ internal partial class ProxyClassesGenerator : BaseGenerator, IFilesGenerator var (namespaceStart, namespaceEnd) = NamespaceBuilder.Build(pd.Namespace); - var accessibility = pd.Accessibility == ProxyClassAccessibility.Internal ? "internal" : "public"; + var accessibility = + pd.Accessibility == ProxyClassAccessibility.Internal ? "internal" : "public"; return $@"//---------------------------------------------------------------------------------------- // @@ -132,9 +156,7 @@ operators} { var type = GetPropertyType(property, out var isReplaced); - var instance = !property.IsStatic ? - "_Instance" : - $"{targetClassSymbol.Symbol}"; + var instance = !property.IsStatic ? "_Instance" : $"{targetClassSymbol.Symbol}"; var propertyName = property.GetSanitizedName(); var instancePropertyName = $"{instance}.{propertyName}"; @@ -169,8 +191,12 @@ operators} string set; if (isReplaced) { - get = getIsPublic ? $"get => Mapster.TypeAdapter.Adapt<{type}>({instancePropertyName}); " : string.Empty; - set = setIsPublic ? $"set => {instancePropertyName} = Mapster.TypeAdapter.Adapt<{property.Type}>(value); " : string.Empty; + get = getIsPublic + ? $"get => Mapster.TypeAdapter.Adapt<{type}>({instancePropertyName}); " + : string.Empty; + set = setIsPublic + ? $"set => {instancePropertyName} = Mapster.TypeAdapter.Adapt<{property.Type}>(value); " + : string.Empty; } else { @@ -183,7 +209,9 @@ operators} str.AppendLine($" {attribute}"); } - str.AppendLine($" public {overrideOrVirtual}{type} {propertyName} {{ {get}{set}}}"); + str.AppendLine( + $" public {overrideOrVirtual}{type} {propertyName} {{ {get}{set}}}" + ); str.AppendLine(); } @@ -208,7 +236,9 @@ operators} methodParameters.Add(MethodParameterBuilder.Build(parameterSymbol, type)); // Do not add the '_' for a 'ref' parameter. - invokeParameters.Add($"{parameterSymbol.GetRefKindPrefix()}{parameterSymbol.GetSanitizedName()}{(!parameterSymbol.IsRef()).IIf("_")}"); + invokeParameters.Add( + $"{parameterSymbol.GetRefKindPrefix()}{parameterSymbol.GetSanitizedName()}{(!parameterSymbol.IsRef()).IIf("_")}" + ); } string overrideOrVirtual = string.Empty; @@ -225,7 +255,10 @@ operators} overrideOrVirtual = "virtual "; } - string returnTypeAsString = GetReplacedTypeAsString(method.ReturnType, out var returnIsReplaced); + string returnTypeAsString = GetReplacedTypeAsString( + method.ReturnType, + out var returnIsReplaced + ); var whereStatement = GetWhereStatementFromMethod(method); @@ -234,12 +267,17 @@ operators} str.AppendLine($" {attribute}"); } - str.AppendLine($" public {overrideOrVirtual}{returnTypeAsString} {method.GetMethodNameWithOptionalTypeParameters()}({string.Join(", ", methodParameters)}){whereStatement}"); + str.AppendLine( + $" public {overrideOrVirtual}{returnTypeAsString} {method.GetMethodNameWithOptionalTypeParameters()}({string.Join(", ", methodParameters)}){whereStatement}" + ); str.AppendLine(@" {"); foreach (var ps in method.Parameters.Where(p => !p.IsRef())) { - var type = FixType(ps.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), ps.Type.NullableAnnotation); + var type = FixType( + ps.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), + ps.Type.NullableAnnotation + ); string normalOrMap = $" = {ps.GetSanitizedName()}"; if (ps.RefKind == RefKind.Out) { @@ -250,7 +288,8 @@ operators} _ = GetParameterType(ps, out var isReplaced); // TODO : response is not used? if (isReplaced) { - normalOrMap = $" = Mapster.TypeAdapter.Adapt<{type}>({ps.GetSanitizedName()})"; + normalOrMap = + $" = Mapster.TypeAdapter.Adapt<{type}>({ps.GetSanitizedName()})"; } } @@ -258,17 +297,24 @@ operators} } var methodName = method.GetMethodNameWithOptionalTypeParameters(); - var alternateReturnVariableName = $"result_{methodName.GetDeterministicHashCodeAsString()}"; + var alternateReturnVariableName = + $"result_{methodName.GetDeterministicHashCodeAsString()}"; - string instance = method.IsStatic ? targetClassSymbol.Symbol.ToFullyQualifiedDisplayString() : "_Instance"; + string instance = method.IsStatic + ? targetClassSymbol.Symbol.ToFullyQualifiedDisplayString() + : "_Instance"; if (returnTypeAsString == "void") { - str.AppendLine($" {instance}.{methodName}({string.Join(", ", invokeParameters)});"); + str.AppendLine( + $" {instance}.{methodName}({string.Join(", ", invokeParameters)});" + ); } else { - str.AppendLine($" var {alternateReturnVariableName} = {instance}.{methodName}({string.Join(", ", invokeParameters)});"); + str.AppendLine( + $" var {alternateReturnVariableName} = {instance}.{methodName}({string.Join(", ", invokeParameters)});" + ); } foreach (var ps in method.Parameters.Where(p => p.RefKind == RefKind.Out)) @@ -279,7 +325,8 @@ operators} var type = GetParameterType(ps, out var isReplaced); if (isReplaced) { - normalOrMap = $" = Mapster.TypeAdapter.Adapt<{type}>({ps.GetSanitizedName()}_)"; + normalOrMap = + $" = Mapster.TypeAdapter.Adapt<{type}>({ps.GetSanitizedName()}_)"; } } @@ -290,7 +337,9 @@ operators} { if (returnIsReplaced) { - str.AppendLine($" return Mapster.TypeAdapter.Adapt<{returnTypeAsString}>({alternateReturnVariableName});"); + str.AppendLine( + $" return Mapster.TypeAdapter.Adapt<{returnTypeAsString}>({alternateReturnVariableName});" + ); } else { @@ -312,7 +361,10 @@ operators} { var name = @event.Key.GetSanitizedName(); var ps = @event.First().Parameters.First(); - var type = ps.GetTypeEnum() == TypeEnum.Complex ? GetParameterType(ps, out _) : ps.Type.ToString(); + var type = + ps.GetTypeEnum() == TypeEnum.Complex + ? GetParameterType(ps, out _) + : ps.Type.ToString(); foreach (var attribute in ps.GetAttributesAsList()) { @@ -340,7 +392,9 @@ operators} private string GenerateOperators(ClassSymbol targetClassSymbol, ProxyData proxyData) { var str = new StringBuilder(); - foreach (var @operator in MemberHelper.GetPublicStaticOperators(targetClassSymbol, proxyData)) + foreach ( + var @operator in MemberHelper.GetPublicStaticOperators(targetClassSymbol, proxyData) + ) { foreach (var attribute in @operator.GetAttributesAsList()) { @@ -360,18 +414,26 @@ operators} { var returnTypeAsString = GetReplacedTypeAsString(@operator.ReturnType, out _); - str.AppendLine($" public static explicit operator {returnTypeAsString}({proxyClassName} {parameter.Name})"); + str.AppendLine( + $" public static explicit operator {returnTypeAsString}({proxyClassName} {parameter.Name})" + ); str.AppendLine(@" {"); - str.AppendLine($" return ({returnTypeAsString}) {parameter.Name}._Instance;"); + str.AppendLine( + $" return ({returnTypeAsString}) {parameter.Name}._Instance;" + ); str.AppendLine(@" }"); } else { var returnTypeAsString = GetReplacedTypeAsString(parameter.Type, out _); - str.AppendLine($" public static implicit operator {proxyClassName}({returnTypeAsString} {parameter.Name})"); + str.AppendLine( + $" public static implicit operator {proxyClassName}({returnTypeAsString} {parameter.Name})" + ); str.AppendLine(@" {"); - str.AppendLine($" return new {proxyClassName}(({targetClassSymbol.Symbol.Name}) {parameter.Name});"); + str.AppendLine( + $" return new {proxyClassName}(({targetClassSymbol.Symbol.Name}) {parameter.Name});" + ); str.AppendLine(@" }"); } @@ -380,4 +442,4 @@ operators} return str.ToString(); } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Models/ClassSymbol.cs b/src/Speckle.ProxyGenerator/Models/ClassSymbol.cs index bc0cd99..fcb91b8 100644 --- a/src/Speckle.ProxyGenerator/Models/ClassSymbol.cs +++ b/src/Speckle.ProxyGenerator/Models/ClassSymbol.cs @@ -2,10 +2,17 @@ using Microsoft.CodeAnalysis; namespace Speckle.ProxyGenerator.Models; -internal record ClassSymbol(INamedTypeSymbol Symbol, List BaseTypes, List Interfaces) +internal record ClassSymbol( + INamedTypeSymbol Symbol, + List BaseTypes, + List Interfaces +) { public override string ToString() { - return Symbol.ToDisplayString(NullableFlowState.None, SymbolDisplayFormat.FullyQualifiedFormat); + return Symbol.ToDisplayString( + NullableFlowState.None, + SymbolDisplayFormat.FullyQualifiedFormat + ); } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Models/ConstraintInfo.cs b/src/Speckle.ProxyGenerator/Models/ConstraintInfo.cs index 0863e0d..a7b253d 100644 --- a/src/Speckle.ProxyGenerator/Models/ConstraintInfo.cs +++ b/src/Speckle.ProxyGenerator/Models/ConstraintInfo.cs @@ -6,4 +6,4 @@ internal record ConstraintInfo(string Type, List Items) { return Items.Any() ? $" where {Type} : {string.Join(", ", Items)}" : string.Empty; } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Models/Context.cs b/src/Speckle.ProxyGenerator/Models/Context.cs index e0712c0..c802acc 100644 --- a/src/Speckle.ProxyGenerator/Models/Context.cs +++ b/src/Speckle.ProxyGenerator/Models/Context.cs @@ -10,4 +10,4 @@ internal record Context public IDictionary Candidates { get; init; } = default!; public Dictionary ReplacedTypes { get; } = new(); -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Models/FileData.cs b/src/Speckle.ProxyGenerator/Models/FileData.cs index 4b68ed8..6201a22 100644 --- a/src/Speckle.ProxyGenerator/Models/FileData.cs +++ b/src/Speckle.ProxyGenerator/Models/FileData.cs @@ -1,3 +1,3 @@ namespace Speckle.ProxyGenerator.Models; -internal record FileData(string FileName, string Text); \ No newline at end of file +internal record FileData(string FileName, string Text); diff --git a/src/Speckle.ProxyGenerator/Models/ProxyData.cs b/src/Speckle.ProxyGenerator/Models/ProxyData.cs index 5680312..4404123 100644 --- a/src/Speckle.ProxyGenerator/Models/ProxyData.cs +++ b/src/Speckle.ProxyGenerator/Models/ProxyData.cs @@ -25,7 +25,8 @@ internal class ProxyData public ProxyClassAccessibility Accessibility { get; } public string[] MembersToIgnore { get; } - public ProxyData(string @namespace, + public ProxyData( + string @namespace, string namespaceDot, string shortInterfaceName, string fullInterfaceName, @@ -34,18 +35,25 @@ internal class ProxyData string fullMetadataTypeName, List usings, bool proxyBaseClasses, - ProxyClassAccessibility accessibility, string[] membersToIgnore) + ProxyClassAccessibility accessibility, + string[] membersToIgnore + ) { Namespace = @namespace ?? throw new ArgumentNullException(nameof(@namespace)); NamespaceDot = namespaceDot ?? throw new ArgumentNullException(nameof(namespaceDot)); - ShortInterfaceName = shortInterfaceName ?? throw new ArgumentNullException(nameof(shortInterfaceName)); - FullInterfaceName = fullInterfaceName ?? throw new ArgumentNullException(nameof(fullInterfaceName)); - FullQualifiedTypeName = fullQualifiedTypeName ?? throw new ArgumentNullException(nameof(fullQualifiedTypeName)); - ShortMetadataName = shortMetadataTypeName ?? throw new ArgumentNullException(nameof(shortMetadataTypeName)); - FullMetadataTypeName = fullMetadataTypeName ?? throw new ArgumentNullException(nameof(fullMetadataTypeName)); + ShortInterfaceName = + shortInterfaceName ?? throw new ArgumentNullException(nameof(shortInterfaceName)); + FullInterfaceName = + fullInterfaceName ?? throw new ArgumentNullException(nameof(fullInterfaceName)); + FullQualifiedTypeName = + fullQualifiedTypeName ?? throw new ArgumentNullException(nameof(fullQualifiedTypeName)); + ShortMetadataName = + shortMetadataTypeName ?? throw new ArgumentNullException(nameof(shortMetadataTypeName)); + FullMetadataTypeName = + fullMetadataTypeName ?? throw new ArgumentNullException(nameof(fullMetadataTypeName)); Usings = usings ?? throw new ArgumentNullException(nameof(usings)); ProxyBaseClasses = proxyBaseClasses; Accessibility = accessibility; MembersToIgnore = membersToIgnore; } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/ProxyInterfaceCodeGenerator.cs b/src/Speckle.ProxyGenerator/ProxyInterfaceCodeGenerator.cs index 1f2d9d9..66004c8 100644 --- a/src/Speckle.ProxyGenerator/ProxyInterfaceCodeGenerator.cs +++ b/src/Speckle.ProxyGenerator/ProxyInterfaceCodeGenerator.cs @@ -40,7 +40,9 @@ class ProxyInterfaceCodeGenerator : ISourceGenerator if (context.SyntaxContextReceiver is not ProxySyntaxReceiver receiver) { - throw new NotSupportedException($"Only {nameof(ProxySyntaxReceiver)} is supported."); + throw new NotSupportedException( + $"Only {nameof(ProxySyntaxReceiver)} is supported." + ); } // https://github.com/reactiveui/refit/blob/main/InterfaceStubGenerator.Core/InterfaceStubGenerator.cs @@ -58,7 +60,8 @@ class ProxyInterfaceCodeGenerator : ISourceGenerator private void GenerateError(GeneratorExecutionContext context, Exception exception) { - var message = $"/*\r\n{nameof(ProxyInterfaceCodeGenerator)}\r\n\r\n[Exception]\r\n{exception}\r\n\r\n[StackTrace]\r\n{exception.StackTrace}*/"; + var message = + $"/*\r\n{nameof(ProxyInterfaceCodeGenerator)}\r\n\r\n[Exception]\r\n{exception}\r\n\r\n[StackTrace]\r\n{exception.StackTrace}*/"; context.AddSource("Error.g", SourceText.From(message, Encoding.UTF8)); } @@ -71,10 +74,17 @@ class ProxyInterfaceCodeGenerator : ISourceGenerator }; var attributeData = _proxyAttributeGenerator.GenerateFile(); - context.GeneratorExecutionContext.AddSource(attributeData.FileName, SourceText.From(attributeData.Text, Encoding.UTF8)); + context.GeneratorExecutionContext.AddSource( + attributeData.FileName, + SourceText.From(attributeData.Text, Encoding.UTF8) + ); } - private static void GeneratePartialInterfaces(GeneratorExecutionContext ctx, ProxySyntaxReceiver receiver, bool supportsNullable) + private static void GeneratePartialInterfaces( + GeneratorExecutionContext ctx, + ProxySyntaxReceiver receiver, + bool supportsNullable + ) { var context = new Context { @@ -85,11 +95,18 @@ class ProxyInterfaceCodeGenerator : ISourceGenerator var partialInterfacesGenerator = new PartialInterfacesGenerator(context, supportsNullable); foreach (var (fileName, text) in partialInterfacesGenerator.GenerateFiles()) { - context.GeneratorExecutionContext.AddSource(fileName, SourceText.From(text, Encoding.UTF8)); + context.GeneratorExecutionContext.AddSource( + fileName, + SourceText.From(text, Encoding.UTF8) + ); } } - private static void GenerateProxyClasses(GeneratorExecutionContext ctx, ProxySyntaxReceiver receiver, bool supportsNullable) + private static void GenerateProxyClasses( + GeneratorExecutionContext ctx, + ProxySyntaxReceiver receiver, + bool supportsNullable + ) { var context = new Context { @@ -100,7 +117,10 @@ class ProxyInterfaceCodeGenerator : ISourceGenerator var proxyClassesGenerator = new ProxyClassesGenerator(context, supportsNullable); foreach (var (fileName, text) in proxyClassesGenerator.GenerateFiles()) { - context.GeneratorExecutionContext.AddSource(fileName, SourceText.From(text, Encoding.UTF8)); + context.GeneratorExecutionContext.AddSource( + fileName, + SourceText.From(text, Encoding.UTF8) + ); } } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/SyntaxReceiver/AttributeArgumentListParser.cs b/src/Speckle.ProxyGenerator/SyntaxReceiver/AttributeArgumentListParser.cs index 7dee24a..3e72290 100644 --- a/src/Speckle.ProxyGenerator/SyntaxReceiver/AttributeArgumentListParser.cs +++ b/src/Speckle.ProxyGenerator/SyntaxReceiver/AttributeArgumentListParser.cs @@ -9,7 +9,10 @@ namespace Speckle.ProxyGenerator.SyntaxReceiver; internal static class AttributeArgumentListParser { - public static ProxyInterfaceGeneratorAttributeArguments ParseAttributeArguments(AttributeArgumentListSyntax? argumentList, SemanticModel semanticModel) + public static ProxyInterfaceGeneratorAttributeArguments ParseAttributeArguments( + AttributeArgumentListSyntax? argumentList, + SemanticModel semanticModel + ) { if (argumentList is null || argumentList.Arguments.Count is < 1 or > 4) { @@ -17,13 +20,25 @@ internal static class AttributeArgumentListParser } ProxyInterfaceGeneratorAttributeArguments result; - if (TryParseAsType(argumentList.Arguments[0].Expression, semanticModel, out var fullyQualifiedDisplayString, out var metadataName)) + if ( + TryParseAsType( + argumentList.Arguments[0].Expression, + semanticModel, + out var fullyQualifiedDisplayString, + out var metadataName + ) + ) { - result = new ProxyInterfaceGeneratorAttributeArguments(fullyQualifiedDisplayString, metadataName); + result = new ProxyInterfaceGeneratorAttributeArguments( + fullyQualifiedDisplayString, + metadataName + ); } else { - throw new ArgumentException("The first argument from the ProxyAttribute should be a Type."); + throw new ArgumentException( + "The first argument from the ProxyAttribute should be a Type." + ); } foreach (var argument in argumentList.Arguments.Skip(1)) @@ -61,7 +76,12 @@ internal static class AttributeArgumentListParser return false; } - private static bool TryParseAsType(ExpressionSyntax expressionSyntax, SemanticModel semanticModel, [NotNullWhen(true)] out string? fullyQualifiedDisplayString, [NotNullWhen(true)] out string? metadataName) + private static bool TryParseAsType( + ExpressionSyntax expressionSyntax, + SemanticModel semanticModel, + [NotNullWhen(true)] out string? fullyQualifiedDisplayString, + [NotNullWhen(true)] out string? metadataName + ) { fullyQualifiedDisplayString = null; metadataName = null; @@ -83,7 +103,13 @@ internal static class AttributeArgumentListParser where TEnum : struct { var enumAsString = expressionSyntax.ToString(); - if (enumAsString.Length > typeof(TEnum).Name.Length && Enum.TryParse(expressionSyntax.ToString().Substring(typeof(TEnum).Name.Length + 1), out value)) + if ( + enumAsString.Length > typeof(TEnum).Name.Length + && Enum.TryParse( + expressionSyntax.ToString().Substring(typeof(TEnum).Name.Length + 1), + out value + ) + ) { return true; } @@ -94,10 +120,15 @@ internal static class AttributeArgumentListParser private static bool TryParseAsStringArray(ExpressionSyntax expressionSyntax, out string[] value) { - if (expressionSyntax is ImplicitArrayCreationExpressionSyntax lmplicitArrayCreationExpressionSyntax) + if ( + expressionSyntax + is ImplicitArrayCreationExpressionSyntax lmplicitArrayCreationExpressionSyntax + ) { var strings = new List(); - foreach (var expression in lmplicitArrayCreationExpressionSyntax.Initializer.Expressions) + foreach ( + var expression in lmplicitArrayCreationExpressionSyntax.Initializer.Expressions + ) { if (expression.GetFirstToken().Value is string s) { diff --git a/src/Speckle.ProxyGenerator/SyntaxReceiver/ProxySyntaxReceiver.cs b/src/Speckle.ProxyGenerator/SyntaxReceiver/ProxySyntaxReceiver.cs index ae93caa..46d99a3 100644 --- a/src/Speckle.ProxyGenerator/SyntaxReceiver/ProxySyntaxReceiver.cs +++ b/src/Speckle.ProxyGenerator/SyntaxReceiver/ProxySyntaxReceiver.cs @@ -9,26 +9,44 @@ namespace Speckle.ProxyGenerator.SyntaxReceiver; internal class ProxySyntaxReceiver : ISyntaxContextReceiver { private const string GlobalPrefix = "global::"; - private static readonly string[] GenerateProxyAttributes = ["ProxyInterfaceGenerator.Proxy", "Proxy"]; + private static readonly string[] GenerateProxyAttributes = + [ + "ProxyInterfaceGenerator.Proxy", + "Proxy" + ]; private static readonly string[] Modifiers = ["public", "partial"]; - public IDictionary CandidateInterfaces { get; } = new Dictionary(); + public IDictionary CandidateInterfaces { get; } = + new Dictionary(); public void OnVisitSyntaxNode(GeneratorSyntaxContext context) { var syntaxNode = context.Node; var semanticModel = context.SemanticModel; - if (syntaxNode is InterfaceDeclarationSyntax interfaceDeclarationSyntax && TryGet(interfaceDeclarationSyntax, out var data, semanticModel!)) + if ( + syntaxNode is InterfaceDeclarationSyntax interfaceDeclarationSyntax + && TryGet(interfaceDeclarationSyntax, out var data, semanticModel!) + ) { CandidateInterfaces.Add(interfaceDeclarationSyntax, data); } } - private static string CreateFullInterfaceName(string ns, BaseTypeDeclarationSyntax classDeclarationSyntax) + private static string CreateFullInterfaceName( + string ns, + BaseTypeDeclarationSyntax classDeclarationSyntax + ) { - return !string.IsNullOrEmpty(ns) ? $"{ns}.{classDeclarationSyntax.Identifier}" : classDeclarationSyntax.Identifier.ToString(); + return !string.IsNullOrEmpty(ns) + ? $"{ns}.{classDeclarationSyntax.Identifier}" + : classDeclarationSyntax.Identifier.ToString(); } - private static bool TryGet(InterfaceDeclarationSyntax interfaceDeclarationSyntax, [NotNullWhen(true)] out ProxyData? data, SemanticModel semanticModel) + + private static bool TryGet( + InterfaceDeclarationSyntax interfaceDeclarationSyntax, + [NotNullWhen(true)] out ProxyData? data, + SemanticModel semanticModel + ) { data = null; @@ -38,7 +56,9 @@ internal class ProxySyntaxReceiver : ISyntaxContextReceiver return false; } - var attributeList = interfaceDeclarationSyntax.AttributeLists.FirstOrDefault(x => x.Attributes.Any(a => GenerateProxyAttributes.Contains(a.Name.ToString()))); + var attributeList = interfaceDeclarationSyntax.AttributeLists.FirstOrDefault(x => + x.Attributes.Any(a => GenerateProxyAttributes.Contains(a.Name.ToString())) + ); if (attributeList is null) { // InterfaceDeclarationSyntax should have the correct attribute @@ -61,7 +81,10 @@ internal class ProxySyntaxReceiver : ISyntaxContextReceiver } } - var fluentBuilderAttributeArguments = AttributeArgumentListParser.ParseAttributeArguments(attributeList.Attributes.FirstOrDefault()?.ArgumentList, semanticModel); + var fluentBuilderAttributeArguments = AttributeArgumentListParser.ParseAttributeArguments( + attributeList.Attributes.FirstOrDefault()?.ArgumentList, + semanticModel + ); var metadataName = fluentBuilderAttributeArguments.MetadataName; var globalNamespace = string.IsNullOrEmpty(ns) ? string.Empty : $"{GlobalPrefix}{ns}"; diff --git a/src/Speckle.ProxyGenerator/Types/FluentBuilderAttributeArguments.cs b/src/Speckle.ProxyGenerator/Types/FluentBuilderAttributeArguments.cs index a5d3e4d..aed4b5e 100644 --- a/src/Speckle.ProxyGenerator/Types/FluentBuilderAttributeArguments.cs +++ b/src/Speckle.ProxyGenerator/Types/FluentBuilderAttributeArguments.cs @@ -1,6 +1,9 @@ namespace Speckle.ProxyGenerator.Types; -internal record ProxyInterfaceGeneratorAttributeArguments(string FullyQualifiedDisplayString, string MetadataName) +internal record ProxyInterfaceGeneratorAttributeArguments( + string FullyQualifiedDisplayString, + string MetadataName +) { public bool ProxyBaseClasses { get; set; } diff --git a/src/Speckle.ProxyGenerator/Types/ProxyInterfaceGeneratorAccessibility.cs b/src/Speckle.ProxyGenerator/Types/ProxyInterfaceGeneratorAccessibility.cs index 7077b99..9a8ef81 100644 --- a/src/Speckle.ProxyGenerator/Types/ProxyInterfaceGeneratorAccessibility.cs +++ b/src/Speckle.ProxyGenerator/Types/ProxyInterfaceGeneratorAccessibility.cs @@ -6,4 +6,4 @@ internal enum ProxyClassAccessibility Public = 0, Internal = 1 -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Utils/MemberHelper.cs b/src/Speckle.ProxyGenerator/Utils/MemberHelper.cs index d235b2a..30267f8 100644 --- a/src/Speckle.ProxyGenerator/Utils/MemberHelper.cs +++ b/src/Speckle.ProxyGenerator/Utils/MemberHelper.cs @@ -10,7 +10,8 @@ internal static class MemberHelper public static IReadOnlyList GetPublicProperties( ClassSymbol classSymbol, ProxyData proxyData, - params Func[] filters) + params Func[] filters + ) { var allFilters = new List>(filters) { @@ -23,43 +24,46 @@ internal static class MemberHelper public static IReadOnlyList GetPublicMethods( ClassSymbol classSymbol, ProxyData proxyData, - Func? filter = null) + Func? filter = null + ) { filter ??= _ => true; - return - GetPublicMembers( + return GetPublicMembers( classSymbol, proxyData, m => m.Kind == SymbolKind.Method, m => m.MethodKind == MethodKind.Ordinary, m => !ExcludedMethods.Contains(m.Name), - filter) + filter + ) .ToArray(); } public static IReadOnlyList GetPublicStaticOperators( ClassSymbol classSymbol, ProxyData proxyData, - Func? filter = null) + Func? filter = null + ) { filter ??= _ => true; - return - GetPublicMembers( - classSymbol, - proxyData, - m => m.Kind == SymbolKind.Method, - m => m.MethodKind == MethodKind.Conversion, - m => !ExcludedMethods.Contains(m.Name), - filter) - .ToArray(); + return GetPublicMembers( + classSymbol, + proxyData, + m => m.Kind == SymbolKind.Method, + m => m.MethodKind == MethodKind.Conversion, + m => !ExcludedMethods.Contains(m.Name), + filter + ) + .ToArray(); } public static IReadOnlyList> GetPublicEvents( ClassSymbol classSymbol, ProxyData proxyData, - Func? filter = null) + Func? filter = null + ) { filter ??= _ => true; @@ -68,8 +72,13 @@ internal static class MemberHelper return GetPublicMembers( classSymbol, proxyData, - m => m.MethodKind is MethodKind.EventAdd or MethodKind.EventRemove/* || m.MethodKind == MethodKind.EventRaise*/, - filter) + m => + m.MethodKind + is MethodKind.EventAdd + or MethodKind.EventRemove /* || m.MethodKind == MethodKind.EventRaise*/ + , + filter + ) .GroupBy(e => e.AssociatedSymbol) .ToArray(); #pragma warning restore RS1024 // Compare symbols correctly @@ -81,9 +90,12 @@ internal static class MemberHelper ClassSymbol classSymbol, ProxyData proxyData, params Func[] filters - ) where T : ISymbol + ) + where T : ISymbol { - var membersQuery = classSymbol.Symbol.GetMembers().OfType() + var membersQuery = classSymbol + .Symbol.GetMembers() + .OfType() .Where(m => m.DeclaredAccessibility == Accessibility.Public); var f = filters.ToList(); @@ -106,7 +118,9 @@ internal static class MemberHelper while (baseType != null && baseType.SpecialType != SpecialType.System_Object) { - var baseMembers = baseType.GetMembers().OfType() + var baseMembers = baseType + .GetMembers() + .OfType() .Where(m => m.DeclaredAccessibility == Accessibility.Public) .Where(x => !ownMemberNames.Contains(x.Name)); @@ -122,4 +136,4 @@ internal static class MemberHelper return allMembers; } -} \ No newline at end of file +} diff --git a/src/Speckle.ProxyGenerator/Utils/NamespaceHelper.cs b/src/Speckle.ProxyGenerator/Utils/NamespaceHelper.cs index 0491523..47c6469 100644 --- a/src/Speckle.ProxyGenerator/Utils/NamespaceHelper.cs +++ b/src/Speckle.ProxyGenerator/Utils/NamespaceHelper.cs @@ -6,10 +6,9 @@ internal static class NamespaceBuilder { var namespaceDefined = !string.IsNullOrEmpty(ns); - return - ( + return ( namespaceDefined ? $"namespace {ns}\r\n{{" : string.Empty, namespaceDefined ? "}" : string.Empty ); } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/AkkaTests.cs b/tests/ProxyInterfaceSourceGeneratorTests/AkkaTests.cs index 39b6c62..33449c4 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/AkkaTests.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/AkkaTests.cs @@ -40,10 +40,7 @@ public class AkkaTests }; // Act - var result = _sut.Execute(new[] - { - sourceFile - }); + var result = _sut.Execute(new[] { sourceFile }); // Assert result.Valid.Should().BeTrue(); @@ -54,8 +51,14 @@ public class AkkaTests var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute builder.Path.Should().EndWith(fileName.fileName); - if (Write) File.WriteAllText($"../../../Destination/AkkaGenerated/{fileName.fileName}", builder.Text); - builder.Text.Should().Be(File.ReadAllText($"../../../Destination/AkkaGenerated/{fileName.fileName}")); + if (Write) + File.WriteAllText( + $"../../../Destination/AkkaGenerated/{fileName.fileName}", + builder.Text + ); + builder + .Text.Should() + .Be(File.ReadAllText($"../../../Destination/AkkaGenerated/{fileName.fileName}")); } } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/InheritedInterfaceTests.cs b/tests/ProxyInterfaceSourceGeneratorTests/InheritedInterfaceTests.cs index 9db5276..e96ac43 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/InheritedInterfaceTests.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/InheritedInterfaceTests.cs @@ -27,17 +27,17 @@ public class InheritedInterfaceTests [Theory] [InlineData(false, false)] [InlineData(true, true)] - public void GenerateFiles_InheritedInterface_InheritFromBaseClass(bool proxyBaseClass, bool inheritBaseInterface) + public void GenerateFiles_InheritedInterface_InheritFromBaseClass( + bool proxyBaseClass, + bool inheritBaseInterface + ) { var name = "Child"; var interfaceName = "I" + name; var proxyName = name + "Proxy"; // Arrange - string[] fileNames = [ - $"{Namespace}.{interfaceName}.g.cs", - $"{Namespace}.{proxyName}.g.cs" - ]; + string[] fileNames = [$"{Namespace}.{interfaceName}.g.cs", $"{Namespace}.{proxyName}.g.cs"]; var path = $"./Source/Disposable/{interfaceName}.cs"; SourceFile sourceFile = CreateSourceFile(path, name, proxyBaseClass); @@ -69,10 +69,7 @@ public class InheritedInterfaceTests var proxyName = name + "Proxy"; // Arrange - string[] fileNames = [ - $"{Namespace}.{interfaceName}.g.cs", - $"{Namespace}.{proxyName}.g.cs" - ]; + string[] fileNames = [$"{Namespace}.{interfaceName}.g.cs", $"{Namespace}.{proxyName}.g.cs"]; var path = $"./Source/Disposable/{interfaceName}.cs"; SourceFile sourceFile = CreateSourceFile(path, name, true); @@ -107,10 +104,7 @@ public class InheritedInterfaceTests var proxyName = name + "Proxy"; // Arrange - string[] fileNames = [ - $"{Namespace}.{interfaceName}.g.cs", - $"{Namespace}.{proxyName}.g.cs" - ]; + string[] fileNames = [$"{Namespace}.{interfaceName}.g.cs", $"{Namespace}.{proxyName}.g.cs"]; var interfaceIndex = 1; var path = $"./Source/Disposable/{interfaceName}.cs"; SourceFile sourceFile = CreateSourceFile(path, name, true); @@ -161,4 +155,4 @@ public class InheritedInterfaceTests builder.Text.Should().Be(File.ReadAllText($"{OutputPath}{fileName.fileName}")); } } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/PnPTests.cs b/tests/ProxyInterfaceSourceGeneratorTests/PnPTests.cs index 5aeee73..5a2ac78 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/PnPTests.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/PnPTests.cs @@ -30,7 +30,6 @@ public class PnPTests "ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb.g.cs", "ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext.g.cs", "ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext.g.cs", - "Microsoft.SharePoint.Client.ClientObjectProxy.g.cs", "Microsoft.SharePoint.Client.SecurableObjectProxy.g.cs", "Microsoft.SharePoint.Client.WebProxy.g.cs", @@ -99,14 +98,16 @@ public class PnPTests }; // Act - var result = _sut.Execute(new[] - { - sourceFileClientObject, - sourceFileSec, - sourceFileWeb, - sourceFileClientRuntimeContext, - sourceFileClientContext - }); + var result = _sut.Execute( + new[] + { + sourceFileClientObject, + sourceFileSec, + sourceFileWeb, + sourceFileClientRuntimeContext, + sourceFileClientContext + } + ); // Assert result.Valid.Should().BeTrue(); @@ -117,8 +118,9 @@ public class PnPTests var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute builder.Path.Should().EndWith(fileName.fileName); - if (Write) File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text); + if (Write) + File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text); builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}")); } } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs index c6be8ea..4f6dd38 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs @@ -72,10 +72,7 @@ public class ProxyInterfaceSourceGeneratorTest }; // Act - var result = _sut.Execute(new[] - { - sourceFile - }); + var result = _sut.Execute(new[] { sourceFile }); // Assert result.Valid.Should().BeTrue(); @@ -86,7 +83,6 @@ public class ProxyInterfaceSourceGeneratorTest return Verify(results); } - [Fact] public Task GenerateFiles_ForClassWithIgnores() { @@ -105,19 +101,18 @@ public class ProxyInterfaceSourceGeneratorTest AttributeToAddToInterface = new ExtraAttribute { Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = new [] + ArgumentList = new[] { - "typeof(ProxyInterfaceSourceGeneratorTests.Source.Foo2)", "false", "ProxyClassAccessibility.Public", + "typeof(ProxyInterfaceSourceGeneratorTests.Source.Foo2)", + "false", + "ProxyClassAccessibility.Public", "new []{\"Weird\",\"NotHere\"}" } } }; // Act - var result = _sut.Execute(new[] - { - sourceFile - }); + var result = _sut.Execute(new[] { sourceFile }); // Assert result.Valid.Should().BeTrue(); @@ -151,10 +146,7 @@ public class ProxyInterfaceSourceGeneratorTest }; // Act - var result = _sut.Execute(new[] - { - sourceFile - }); + var result = _sut.Execute(new[] { sourceFile }); // Assert result.Valid.Should().BeTrue(); @@ -165,7 +157,8 @@ public class ProxyInterfaceSourceGeneratorTest var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute builder.Path.Should().EndWith(fileName.fileName); - if (Write) File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text); + if (Write) + File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text); builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}")); } } @@ -193,10 +186,7 @@ public class ProxyInterfaceSourceGeneratorTest }; // Act - var result = _sut.Execute(new[] - { - sourceFile - }); + var result = _sut.Execute(new[] { sourceFile }); // Assert result.Valid.Should().BeTrue(); @@ -207,7 +197,8 @@ public class ProxyInterfaceSourceGeneratorTest var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute builder.Path.Should().EndWith(fileName.fileName); - if (Write) File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text); + if (Write) + File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text); builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}")); } } @@ -235,10 +226,7 @@ public class ProxyInterfaceSourceGeneratorTest }; // Act - var result = _sut.Execute(new[] - { - sourceFile - }); + var result = _sut.Execute(new[] { sourceFile }); // Assert result.Valid.Should().BeTrue(); @@ -249,15 +237,13 @@ public class ProxyInterfaceSourceGeneratorTest var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute builder.Path.Should().EndWith(fileName.fileName); - if (Write) File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text); + if (Write) + File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text); builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}")); } var name = "stef"; - var operatorTest = new OperatorTest - { - Name = name - }; + var operatorTest = new OperatorTest { Name = name }; string name1 = (string)operatorTest; name1.Should().Be(name); @@ -273,11 +259,7 @@ public class ProxyInterfaceSourceGeneratorTest public void GenerateFiles_When_NoNamespace_Should_GenerateCorrectFiles() { // Arrange - var fileNames = new[] - { - "INoNamespace.g.cs", - "NoNamespaceProxy.g.cs" - }; + var fileNames = new[] { "INoNamespace.g.cs", "NoNamespaceProxy.g.cs" }; var path = "./Source/INoNamespace.cs"; var sourceFile = new SourceFile @@ -292,10 +274,7 @@ public class ProxyInterfaceSourceGeneratorTest }; // Act - var result = _sut.Execute(new[] - { - sourceFile - }); + var result = _sut.Execute(new[] { sourceFile }); // Assert result.Valid.Should().BeTrue(); @@ -306,7 +285,8 @@ public class ProxyInterfaceSourceGeneratorTest var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute builder.Path.Should().EndWith(fileName.fileName); - if (Write) File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text); + if (Write) + File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text); builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}")); } } @@ -334,10 +314,7 @@ public class ProxyInterfaceSourceGeneratorTest }; // Act - var result = _sut.Execute(new[] - { - sourceFile - }); + var result = _sut.Execute(new[] { sourceFile }); // Assert result.Valid.Should().BeTrue(); @@ -348,7 +325,8 @@ public class ProxyInterfaceSourceGeneratorTest var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute builder.Path.Should().EndWith(fileName.fileName); - if (Write) File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text); + if (Write) + File.WriteAllText($"../../../Destination/{fileName.fileName}", builder.Text); builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}")); } } @@ -359,7 +337,8 @@ public class ProxyInterfaceSourceGeneratorTest // Arrange var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs"; var interfaceFilename = "ProxyInterfaceSourceGeneratorTests.Source.IPersonExtends.g.cs"; - var proxyClassFilename = "ProxyInterfaceSourceGeneratorTests.Source.PersonExtendsProxy.g.cs"; + var proxyClassFilename = + "ProxyInterfaceSourceGeneratorTests.Source.PersonExtendsProxy.g.cs"; var path = "./Source/IPersonExtends.cs"; var sourceFile = new SourceFile @@ -369,7 +348,11 @@ public class ProxyInterfaceSourceGeneratorTest AttributeToAddToInterface = new ExtraAttribute { Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = new[] { "typeof(ProxyInterfaceSourceGeneratorTests.Source.PersonExtends)", "true" } + ArgumentList = new[] + { + "typeof(ProxyInterfaceSourceGeneratorTests.Source.PersonExtends)", + "true" + } } }; @@ -389,16 +372,24 @@ public class ProxyInterfaceSourceGeneratorTest @interface.FilePath.Should().EndWith(interfaceFilename); var interfaceCode = @interface.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{interfaceFilename}", interfaceCode); - interfaceCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceFilename}")); + if (Write) + File.WriteAllText($"../../../Destination/{interfaceFilename}", interfaceCode); + interfaceCode + .Should() + .NotBeNullOrEmpty() + .And.Be(File.ReadAllText($"../../../Destination/{interfaceFilename}")); // Assert Proxy var proxyClass = result.Files[2].SyntaxTree; proxyClass.FilePath.Should().EndWith(proxyClassFilename); var proxyCode = proxyClass.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{proxyClassFilename}", proxyCode); - proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassFilename}")); + if (Write) + File.WriteAllText($"../../../Destination/{proxyClassFilename}", proxyCode); + proxyCode + .Should() + .NotBeNullOrEmpty() + .And.Be(File.ReadAllText($"../../../Destination/{proxyClassFilename}")); } [Fact] @@ -406,7 +397,8 @@ public class ProxyInterfaceSourceGeneratorTest { // Arrange var interfaceFilename = "ProxyInterfaceSourceGeneratorTests.Source.ITestClassInternal.g.cs"; - var proxyClassFilename = "ProxyInterfaceSourceGeneratorTests.Source.TestClassInternalProxy.g.cs"; + var proxyClassFilename = + "ProxyInterfaceSourceGeneratorTests.Source.TestClassInternalProxy.g.cs"; var path = "./Source/ITestClassInternal.cs"; var sourceFile = new SourceFile @@ -416,7 +408,11 @@ public class ProxyInterfaceSourceGeneratorTest AttributeToAddToInterface = new ExtraAttribute { Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = new[] { "typeof(ProxyInterfaceSourceGeneratorTests.Source.TestClassInternal)", "ProxyClassAccessibility.Internal" } + ArgumentList = new[] + { + "typeof(ProxyInterfaceSourceGeneratorTests.Source.TestClassInternal)", + "ProxyClassAccessibility.Internal" + } } }; @@ -432,16 +428,24 @@ public class ProxyInterfaceSourceGeneratorTest @interface.FilePath.Should().EndWith(interfaceFilename); var interfaceCode = @interface.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{interfaceFilename}", interfaceCode); - interfaceCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceFilename}")); + if (Write) + File.WriteAllText($"../../../Destination/{interfaceFilename}", interfaceCode); + interfaceCode + .Should() + .NotBeNullOrEmpty() + .And.Be(File.ReadAllText($"../../../Destination/{interfaceFilename}")); // Assert Proxy var proxyClass = result.Files[2].SyntaxTree; proxyClass.FilePath.Should().EndWith(proxyClassFilename); var proxyCode = proxyClass.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{proxyClassFilename}", proxyCode); - proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassFilename}")); + if (Write) + File.WriteAllText($"../../../Destination/{proxyClassFilename}", proxyCode); + proxyCode + .Should() + .NotBeNullOrEmpty() + .And.Be(File.ReadAllText($"../../../Destination/{proxyClassFilename}")); } [Fact] @@ -489,41 +493,56 @@ public class ProxyInterfaceSourceGeneratorTest var attribute = result.Files[0].SyntaxTree; attribute.FilePath.Should().EndWith(attributeFilename); - // Assert interface Human var interfaceHuman = result.Files[1].SyntaxTree; interfaceHuman.FilePath.Should().EndWith(interfaceHumanFilename); var interfaceCodeHuman = interfaceHuman.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{interfaceHumanFilename}", interfaceCodeHuman); - interfaceCodeHuman.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceHumanFilename}")); - + if (Write) + File.WriteAllText($"../../../Destination/{interfaceHumanFilename}", interfaceCodeHuman); + interfaceCodeHuman + .Should() + .NotBeNullOrEmpty() + .And.Be(File.ReadAllText($"../../../Destination/{interfaceHumanFilename}")); // Assert interface Person var interfacePerson = result.Files[2].SyntaxTree; interfacePerson.FilePath.Should().EndWith(interfacePersonFilename); var interfaceCodePerson = interfacePerson.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{interfacePersonFilename}", interfaceCodePerson); - interfaceCodePerson.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfacePersonFilename}")); - + if (Write) + File.WriteAllText( + $"../../../Destination/{interfacePersonFilename}", + interfaceCodePerson + ); + interfaceCodePerson + .Should() + .NotBeNullOrEmpty() + .And.Be(File.ReadAllText($"../../../Destination/{interfacePersonFilename}")); // Assert Proxy Human var proxyClassHuman = result.Files[3].SyntaxTree; proxyClassHuman.FilePath.Should().EndWith(proxyClassHumanFilename); var proxyCodeHuman = proxyClassHuman.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{proxyClassHumanFilename}", proxyCodeHuman); - proxyCodeHuman.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassHumanFilename}")); - + if (Write) + File.WriteAllText($"../../../Destination/{proxyClassHumanFilename}", proxyCodeHuman); + proxyCodeHuman + .Should() + .NotBeNullOrEmpty() + .And.Be(File.ReadAllText($"../../../Destination/{proxyClassHumanFilename}")); // Assert Proxy Person var proxyClassPerson = result.Files[4].SyntaxTree; proxyClassPerson.FilePath.Should().EndWith(proxyClassPersonFilename); var proxyCode = proxyClassPerson.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{proxyClassPersonFilename}", proxyCode); - proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassPersonFilename}")); + if (Write) + File.WriteAllText($"../../../Destination/{proxyClassPersonFilename}", proxyCode); + proxyCode + .Should() + .NotBeNullOrEmpty() + .And.Be(File.ReadAllText($"../../../Destination/{proxyClassPersonFilename}")); var personProxy = new PersonProxy(new Person()); @@ -538,9 +557,11 @@ public class ProxyInterfaceSourceGeneratorTest { // Arrange var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs"; - var interfaceIHttpClientFilename = "ProxyInterfaceSourceGeneratorTests.Source.IHttpClient.g.cs"; + var interfaceIHttpClientFilename = + "ProxyInterfaceSourceGeneratorTests.Source.IHttpClient.g.cs"; var proxyClassIHttpClientFilename = "System.Net.Http.HttpClientProxy.g.cs"; - var interfaceIHttpMessageInvokerFilename = "ProxyInterfaceSourceGeneratorTests.Source.IHttpMessageInvoker.g.cs"; + var interfaceIHttpMessageInvokerFilename = + "ProxyInterfaceSourceGeneratorTests.Source.IHttpMessageInvoker.g.cs"; var proxyClassIHttpMessageInvokerFilename = "System.Net.Http.HttpMessageInvokerProxy.g.cs"; var pathIHttpClient = "./Source/IHttpClient.cs"; @@ -578,41 +599,69 @@ public class ProxyInterfaceSourceGeneratorTest var attribute = result.Files[0].SyntaxTree; attribute.FilePath.Should().EndWith(attributeFilename); - // Assert interface IHttpClient var interfaceIHttpClient = result.Files[1].SyntaxTree; interfaceIHttpClient.FilePath.Should().EndWith(interfaceIHttpClientFilename); var interfaceCodeIHttpClient = interfaceIHttpClient.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{interfaceIHttpClientFilename}", interfaceCodeIHttpClient); - interfaceCodeIHttpClient.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceIHttpClientFilename}")); - + if (Write) + File.WriteAllText( + $"../../../Destination/{interfaceIHttpClientFilename}", + interfaceCodeIHttpClient + ); + interfaceCodeIHttpClient + .Should() + .NotBeNullOrEmpty() + .And.Be(File.ReadAllText($"../../../Destination/{interfaceIHttpClientFilename}")); // Assert interface IHttpMessageInvoker var interfaceIMessageInvoker = result.Files[2].SyntaxTree; interfaceIMessageInvoker.FilePath.Should().EndWith(interfaceIHttpMessageInvokerFilename); var interfaceCodeIMessageInvoker = interfaceIMessageInvoker.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{interfaceIHttpMessageInvokerFilename}", interfaceCodeIMessageInvoker); - interfaceCodeIMessageInvoker.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceIHttpMessageInvokerFilename}")); - + if (Write) + File.WriteAllText( + $"../../../Destination/{interfaceIHttpMessageInvokerFilename}", + interfaceCodeIMessageInvoker + ); + interfaceCodeIMessageInvoker + .Should() + .NotBeNullOrEmpty() + .And.Be( + File.ReadAllText($"../../../Destination/{interfaceIHttpMessageInvokerFilename}") + ); // Assert Proxy IHttpClient var proxyClassIHttpClient = result.Files[3].SyntaxTree; proxyClassIHttpClient.FilePath.Should().EndWith(proxyClassIHttpClientFilename); var proxyCodeIHttpClient = proxyClassIHttpClient.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{proxyClassIHttpClientFilename}", proxyCodeIHttpClient); - proxyCodeIHttpClient.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassIHttpClientFilename}")); - + if (Write) + File.WriteAllText( + $"../../../Destination/{proxyClassIHttpClientFilename}", + proxyCodeIHttpClient + ); + proxyCodeIHttpClient + .Should() + .NotBeNullOrEmpty() + .And.Be(File.ReadAllText($"../../../Destination/{proxyClassIHttpClientFilename}")); // Assert Proxy IHttpMessageInvoker var proxyClassIMessageInvoker = result.Files[4].SyntaxTree; proxyClassIMessageInvoker.FilePath.Should().EndWith(proxyClassIHttpMessageInvokerFilename); var proxyIMessageInvoker = proxyClassIMessageInvoker.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{proxyClassIHttpMessageInvokerFilename}", proxyIMessageInvoker); - proxyIMessageInvoker.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassIHttpMessageInvokerFilename}")); + if (Write) + File.WriteAllText( + $"../../../Destination/{proxyClassIHttpMessageInvokerFilename}", + proxyIMessageInvoker + ); + proxyIMessageInvoker + .Should() + .NotBeNullOrEmpty() + .And.Be( + File.ReadAllText($"../../../Destination/{proxyClassIHttpMessageInvokerFilename}") + ); } [Fact] @@ -623,8 +672,10 @@ public class ProxyInterfaceSourceGeneratorTest foreach (var x in new[] { 1, 2 }) { var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs"; - var interfaceFilename = $"ProxyInterfaceSourceGeneratorTests.Namespace{x}.I{@class}.g.cs"; - var proxyClassFilename = $"ProxyInterfaceSourceGeneratorTests.Namespace{x}.{@class}Proxy.g.cs"; + var interfaceFilename = + $"ProxyInterfaceSourceGeneratorTests.Namespace{x}.I{@class}.g.cs"; + var proxyClassFilename = + $"ProxyInterfaceSourceGeneratorTests.Namespace{x}.{@class}Proxy.g.cs"; var path = $"./Source/I{@class}{x}.cs"; var sourceFile = new SourceFile @@ -634,7 +685,11 @@ public class ProxyInterfaceSourceGeneratorTest AttributeToAddToInterface = new ExtraAttribute { Name = "ProxyInterfaceGenerator.Proxy", - ArgumentList = new[] { $"typeof(ProxyInterfaceSourceGeneratorTests.Namespace{x}.{@class})", "true" } + ArgumentList = new[] + { + $"typeof(ProxyInterfaceSourceGeneratorTests.Namespace{x}.{@class})", + "true" + } } }; @@ -654,18 +709,24 @@ public class ProxyInterfaceSourceGeneratorTest @interface.FilePath.Should().EndWith(interfaceFilename); var interfaceCode = @interface.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{interfaceFilename}", interfaceCode); - interfaceCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceFilename}")); + if (Write) + File.WriteAllText($"../../../Destination/{interfaceFilename}", interfaceCode); + interfaceCode + .Should() + .NotBeNullOrEmpty() + .And.Be(File.ReadAllText($"../../../Destination/{interfaceFilename}")); // Assert Proxy var proxyClass = result.Files[2].SyntaxTree; proxyClass.FilePath.Should().EndWith(proxyClassFilename); var proxyCode = proxyClass.ToString(); - if (Write) File.WriteAllText($"../../../Destination/{proxyClassFilename}", proxyCode); - proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassFilename}")); + if (Write) + File.WriteAllText($"../../../Destination/{proxyClassFilename}", proxyCode); + proxyCode + .Should() + .NotBeNullOrEmpty() + .And.Be(File.ReadAllText($"../../../Destination/{proxyClassFilename}")); } - - } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/AkkaActor/ILocalActorRefProvider.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/AkkaActor/ILocalActorRefProvider.cs index bd959e2..b6be6ce 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/AkkaActor/ILocalActorRefProvider.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/AkkaActor/ILocalActorRefProvider.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.AkkaActor { - public partial interface ILocalActorRefProvider - { - } -} \ No newline at end of file + public partial interface ILocalActorRefProvider { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/AkkaExamples/ILocalActorRefProvider.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/AkkaExamples/ILocalActorRefProvider.cs index bd959e2..b6be6ce 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/AkkaExamples/ILocalActorRefProvider.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/AkkaExamples/ILocalActorRefProvider.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.AkkaActor { - public partial interface ILocalActorRefProvider - { - } -} \ No newline at end of file + public partial interface ILocalActorRefProvider { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Bar.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Bar.cs index 5c2c681..5e85ec2 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Bar.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Bar.cs @@ -1,5 +1,3 @@ namespace ProxyInterfaceSourceGeneratorTests.Source; -public class Bar -{ -} \ No newline at end of file +public class Bar { } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassInNamespace1.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassInNamespace1.cs index c5a1490..f0309f6 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassInNamespace1.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassInNamespace1.cs @@ -1,7 +1,5 @@ // ReSharper disable once CheckNamespace namespace ProxyInterfaceSourceGeneratorTests.Namespace1 { - public class ClassInNamespace - { - } -} \ No newline at end of file + public class ClassInNamespace { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassInNamespace2.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassInNamespace2.cs index a485120..e1f5a8a 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassInNamespace2.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/ClassInNamespace2.cs @@ -1,7 +1,5 @@ // ReSharper disable once CheckNamespace namespace ProxyInterfaceSourceGeneratorTests.Namespace2 { - public class ClassInNamespace - { - } -} \ No newline at end of file + public class ClassInNamespace { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/Child.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/Child.cs index ae33ecf..975f506 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/Child.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/Child.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable { - public class Child : Parent - { - } -} \ No newline at end of file + public class Child : Parent { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/Explicit.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/Explicit.cs index 0ba143e..8cd6c1e 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/Explicit.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/Explicit.cs @@ -6,15 +6,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable event EventHandler? IUpdate.Update { - add - { - throw new NotSupportedException(); - } - - remove - { - throw new NotSupportedException(); - } + add { throw new NotSupportedException(); } + remove { throw new NotSupportedException(); } } void IDisposable.Dispose() @@ -22,4 +15,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable throw new NotSupportedException(); } } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IChild.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IChild.cs index dd50972..4360380 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IChild.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IChild.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable { - public partial interface IChild - { - } -} \ No newline at end of file + public partial interface IChild { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IExplicit.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IExplicit.cs index 4bfc5b9..76be43f 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IExplicit.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IExplicit.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable { - public partial interface IExplicit - { - } -} \ No newline at end of file + public partial interface IExplicit { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IParent.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IParent.cs index d5e2fb1..f2b6cc3 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IParent.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IParent.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable { - public partial interface IParent - { - } -} \ No newline at end of file + public partial interface IParent { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IUpdate.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IUpdate.cs index 6ace218..6c6b437 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IUpdate.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/IUpdate.cs @@ -6,4 +6,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable string Name { get; } } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/Parent.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/Parent.cs index f17308d..567ee10 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/Parent.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Disposable/Parent.cs @@ -42,4 +42,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable // Dispose(disposing: false); // } } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Foo2.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Foo2.cs index 00b7e99..b0d460b 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Foo2.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Foo2.cs @@ -20,13 +20,15 @@ public class Foo2 //} [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public Foo2[] Foos { get; set; }= null!; + public Foo2[] Foos { get; set; } = null!; public Foo2[] DoSomethingAndGetAnArrayOfFoos() { return new[] { new Foo2() }; } + public int Weird { get; set; } + public int Weird2() { return 0; diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Generic.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Generic.cs index 76b28c4..6a0c0af 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Generic.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Generic.cs @@ -7,4 +7,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source return value; } } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Human.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Human.cs index 75a9fd2..8b2b499 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Human.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Human.cs @@ -6,9 +6,6 @@ namespace ProxyInterfaceSourceGeneratorTests.Source public string GetterOnly => "x"; - public void Dispose() - { - - } + public void Dispose() { } } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassInNamespace1.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassInNamespace1.cs index ea5f7bd..63efac5 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassInNamespace1.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassInNamespace1.cs @@ -1,7 +1,5 @@ // ReSharper disable once CheckNamespace namespace ProxyInterfaceSourceGeneratorTests.Namespace1 { - public partial interface IClassInNamespace - { - } -} \ No newline at end of file + public partial interface IClassInNamespace { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassInNamespace2.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassInNamespace2.cs index 25dcc6b..8fa8e58 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassInNamespace2.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IClassInNamespace2.cs @@ -1,7 +1,5 @@ // ReSharper disable once CheckNamespace namespace ProxyInterfaceSourceGeneratorTests.Namespace2 { - public partial interface IClassInNamespace - { - } -} \ No newline at end of file + public partial interface IClassInNamespace { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IFoo.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IFoo.cs index 74e0d49..d39b674 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IFoo.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IFoo.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { - public partial interface IFoo - { - } -} \ No newline at end of file + public partial interface IFoo { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IFoo2.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IFoo2.cs index c10a3a4..551c60c 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IFoo2.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IFoo2.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { - public partial interface IFoo2 - { - } -} \ No newline at end of file + public partial interface IFoo2 { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IGeneric.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IGeneric.cs index 4a80576..9b31b44 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IGeneric.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IGeneric.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { - public partial interface IGeneric - { - } -} \ No newline at end of file + public partial interface IGeneric { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpClient.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpClient.cs index d0898e9..3765f18 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpClient.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpClient.cs @@ -1,5 +1,3 @@ namespace ProxyInterfaceSourceGeneratorTests.Source; -public partial interface IHttpClient : IHttpMessageInvoker -{ -} \ No newline at end of file +public partial interface IHttpClient : IHttpMessageInvoker { } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpMessageInvoker.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpMessageInvoker.cs index f19317e..c0f25d6 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpMessageInvoker.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpMessageInvoker.cs @@ -1,5 +1,3 @@ namespace ProxyInterfaceSourceGeneratorTests.Source; -public partial interface IHttpMessageInvoker -{ -} \ No newline at end of file +public partial interface IHttpMessageInvoker { } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IHuman.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IHuman.cs index 22ba8b1..c94703f 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IHuman.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IHuman.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { - public partial interface IHuman - { - } -} \ No newline at end of file + public partial interface IHuman { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IMixedVisibility.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IMixedVisibility.cs index 5ee0fdb..b2f1b43 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IMixedVisibility.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IMixedVisibility.cs @@ -1,5 +1,3 @@ namespace ProxyInterfaceSourceGeneratorTests.Source; -public partial interface IMixedVisibility -{ -} \ No newline at end of file +public partial interface IMixedVisibility { } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IMyStruct.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IMyStruct.cs index ed8a7b9..2792b41 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IMyStruct.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IMyStruct.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { - public partial interface IMyStruct - { - } -} \ No newline at end of file + public partial interface IMyStruct { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/INoNamespace.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/INoNamespace.cs index 2f2d42c..5e168b4 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/INoNamespace.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/INoNamespace.cs @@ -1,4 +1,2 @@ // ReSharper disable once CheckNamespace -public partial interface INoNamespace -{ -} \ No newline at end of file +public partial interface INoNamespace { } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IOperatorTest.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IOperatorTest.cs index e7c9802..f9130d6 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IOperatorTest.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IOperatorTest.cs @@ -1,6 +1,4 @@ // file-scoped namespace ! namespace ProxyInterfaceSourceGeneratorTests.Source; -public partial interface IOperatorTest -{ -} \ No newline at end of file +public partial interface IOperatorTest { } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IPerson.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IPerson.cs index e0a3d37..71da7f9 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IPerson.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IPerson.cs @@ -1,6 +1,4 @@ // file-scoped namespace ! namespace ProxyInterfaceSourceGeneratorTests.Source; -public partial interface IPerson : IHuman -{ -} \ No newline at end of file +public partial interface IPerson : IHuman { } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IPersonExtends.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IPersonExtends.cs index 8d37a42..8240fec 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IPersonExtends.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IPersonExtends.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { - public partial interface IPersonExtends - { - } -} \ No newline at end of file + public partial interface IPersonExtends { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/ITestClassInternal.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/ITestClassInternal.cs index 049dc9f..f4a468b 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/ITestClassInternal.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/ITestClassInternal.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { - public partial interface ITestClassInternal - { - } -} \ No newline at end of file + public partial interface ITestClassInternal { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IÜberGeneric.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IÜberGeneric.cs index 4e2e819..8fd2008 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/IÜberGeneric.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IÜberGeneric.cs @@ -6,7 +6,5 @@ using System.Threading.Tasks; namespace ProxyInterfaceSourceGeneratorTests.Source { - public interface IÜberGeneric - { - } + public interface IÜberGeneric { } } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/MixedVisibility.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/MixedVisibility.cs index 035b30b..5eceded 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/MixedVisibility.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/MixedVisibility.cs @@ -5,5 +5,5 @@ namespace ProxyInterfaceSourceGeneratorTests.Source; public class MixedVisibility { [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public string Foo { get; protected set; } = null!;//<- this will generate bad code + public string Foo { get; protected set; } = null!; //<- this will generate bad code } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/MyStruct.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/MyStruct.cs index 62a10de..ad065e2 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/MyStruct.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/MyStruct.cs @@ -3,4 +3,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source; public struct MyStruct { public int Id { get; set; } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/NoNamespace.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/NoNamespace.cs index 31cd3c6..a514e54 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/NoNamespace.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/NoNamespace.cs @@ -3,4 +3,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source; public class NoNamespace { public bool Test { get; set; } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/OperatorTest.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/OperatorTest.cs index 0cbd338..e8b02dd 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/OperatorTest.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/OperatorTest.cs @@ -9,18 +9,12 @@ namespace ProxyInterfaceSourceGeneratorTests.Source // Operator : implicit public static implicit operator OperatorTest(string name) { - return new() - { - Name = name - }; + return new() { Name = name }; } - + public static implicit operator OperatorTest(int? id) { - return new() - { - Id = id - }; + return new() { Id = id }; } // Operator : explicit @@ -43,4 +37,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source var s = (string)operatorTest; } } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Person.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Person.cs index e98a4fb..77f62bd 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Person.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Person.cs @@ -25,23 +25,25 @@ namespace ProxyInterfaceSourceGeneratorTests.Source public IList AddHuman(Human h) { - return new List { h, new Human { IsAlive = true } }; + return new List + { + h, + new Human { IsAlive = true } + }; } [Display(ResourceType = typeof(PeriodicTimer))] [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public string Name { get; set; }= null!; + public string Name { get; set; } = null!; public string? StringNullable { get; set; } public long? NullableLong { get; } [SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")] - public object @object { get; set; }= null!; + public object @object { get; set; } = null!; - public void Void() - { - } + public void Void() { } public string HelloWorld(string name) { @@ -68,9 +70,7 @@ namespace ProxyInterfaceSourceGeneratorTests.Source return $"Hello {ch} !"; } - public void WithParams(params string[] values) - { - } + public void WithParams(params string[] values) { } public string Add(string s, string @string) { @@ -117,11 +117,14 @@ namespace ProxyInterfaceSourceGeneratorTests.Source return Task.FromResult((string?)""); } - public void CreateInvokeHttpClient(int i = 5, string? appId = null, IReadOnlyDictionary? metadata = null, CancellationToken token = default) - { - } + public void CreateInvokeHttpClient( + int i = 5, + string? appId = null, + IReadOnlyDictionary? metadata = null, + CancellationToken token = default + ) { } - public bool TryParse(string s1, [NotNullWhen(true)]params int[]? ii) + public bool TryParse(string s1, [NotNullWhen(true)] params int[]? ii) { ii = null; return false; diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/PersonExtends.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/PersonExtends.cs index dafe10a..7a7b927 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/PersonExtends.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/PersonExtends.cs @@ -17,18 +17,14 @@ namespace ProxyInterfaceSourceGeneratorTests.Source public object @object { get; set; } = null!; - public void Void() - { - } + public void Void() { } public string HelloWorld(string name) { return $"Hello {name} !"; } - public void WithParams(params string[] values) - { - } + public void WithParams(params string[] values) { } public string Add(string s, string @string) { @@ -67,4 +63,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source return Task.FromResult((string?)""); } } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IClientContext.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IClientContext.cs index 5065424..bb675f3 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IClientContext.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IClientContext.cs @@ -2,8 +2,5 @@ using Microsoft.SharePoint.Client; namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { - public partial interface IClientContext - { - - } -} \ No newline at end of file + public partial interface IClientContext { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IClientObject.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IClientObject.cs index 727653c..c433221 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IClientObject.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IClientObject.cs @@ -1,6 +1,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { - public partial interface IClientObject - { - } + public partial interface IClientObject { } } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IClientRuntimeContext.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IClientRuntimeContext.cs index fe60473..558f08d 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IClientRuntimeContext.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IClientRuntimeContext.cs @@ -1,8 +1,6 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { - public partial interface IClientRuntimeContext - { - } + public partial interface IClientRuntimeContext { } } namespace ProxyInterfaceSourceGeneratorTests.Source.PnP @@ -22,6 +20,5 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.PnP //{ // var x = CastTo2(new ClientObjectProxy(default)); //} - } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/ISecurableObject.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/ISecurableObject.cs index e233282..2e5f435 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/ISecurableObject.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/ISecurableObject.cs @@ -3,7 +3,5 @@ using Microsoft.SharePoint.Client; namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { // [ProxyInterfaceGenerator.Proxy(typeof(SecurableObject))] - public partial interface ISecurableObject : IClientObject - { - } -} \ No newline at end of file + public partial interface ISecurableObject : IClientObject { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IWeb.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IWeb.cs index 8a3f086..7432f96 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IWeb.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/PnP/IWeb.cs @@ -2,7 +2,5 @@ using Microsoft.SharePoint.Client; namespace ProxyInterfaceSourceGeneratorTests.Source.PnP { - public partial interface IWeb : ISecurableObject - { - } -} \ No newline at end of file + public partial interface IWeb : ISecurableObject { } +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/TestClassInternal.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/TestClassInternal.cs index 488d96f..cd1db16 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/TestClassInternal.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/TestClassInternal.cs @@ -4,4 +4,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { public bool Test { get; set; } } -} \ No newline at end of file +} diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/ÜberGeneric.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/ÜberGeneric.cs index 2f914cf..3b9794a 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/ÜberGeneric.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/ÜberGeneric.cs @@ -14,4 +14,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source public TKey Test(TKey value) => value; } -} \ No newline at end of file +}