add csharpier
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"isRoot": true,
|
||||||
|
"tools": {
|
||||||
|
"csharpier": {
|
||||||
|
"version": "0.28.2",
|
||||||
|
"commands": [
|
||||||
|
"dotnet-csharpier"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ namespace ProxyInterfaceConsumer
|
|||||||
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
||||||
public event EventHandler<EventArgs> MyEvent = null!;
|
public event EventHandler<EventArgs> MyEvent = null!;
|
||||||
public int Weird { get; set; }
|
public int Weird { get; set; }
|
||||||
|
|
||||||
public int Weird2()
|
public int Weird2()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -3,11 +3,7 @@ using System.Net.Http;
|
|||||||
namespace ProxyInterfaceConsumer.Http;
|
namespace ProxyInterfaceConsumer.Http;
|
||||||
|
|
||||||
[ProxyInterfaceGenerator.Proxy(typeof(HttpClient), true)]
|
[ProxyInterfaceGenerator.Proxy(typeof(HttpClient), true)]
|
||||||
public partial interface IHttpClient : IHttpMessageInvoker
|
public partial interface IHttpClient : IHttpMessageInvoker { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[ProxyInterfaceGenerator.Proxy(typeof(HttpMessageInvoker))]
|
[ProxyInterfaceGenerator.Proxy(typeof(HttpMessageInvoker))]
|
||||||
public partial interface IHttpMessageInvoker
|
public partial interface IHttpMessageInvoker { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -13,96 +13,212 @@ namespace ProxyInterfaceConsumer.Http;
|
|||||||
public static class IHttpClientExtensions
|
public static class IHttpClientExtensions
|
||||||
{
|
{
|
||||||
#region PostAsJsonAsync
|
#region PostAsJsonAsync
|
||||||
public static Task<HttpResponseMessage> PostAsJsonAsync<TValue>(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default)
|
public static Task<HttpResponseMessage> PostAsJsonAsync<TValue>(
|
||||||
|
this IHttpClient client,
|
||||||
|
[StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri,
|
||||||
|
TValue value,
|
||||||
|
JsonSerializerOptions? options = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.PostAsJsonAsync(requestUri, value, options, cancellationToken);
|
return client._Instance.PostAsJsonAsync(requestUri, value, options, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<HttpResponseMessage> PostAsJsonAsync<TValue>(this IHttpClient client, Uri? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default)
|
public static Task<HttpResponseMessage> PostAsJsonAsync<TValue>(
|
||||||
|
this IHttpClient client,
|
||||||
|
Uri? requestUri,
|
||||||
|
TValue value,
|
||||||
|
JsonSerializerOptions? options = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.PostAsJsonAsync(requestUri, value, options, cancellationToken);
|
return client._Instance.PostAsJsonAsync(requestUri, value, options, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<HttpResponseMessage> PostAsJsonAsync<TValue>(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, CancellationToken cancellationToken)
|
public static Task<HttpResponseMessage> PostAsJsonAsync<TValue>(
|
||||||
|
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<HttpResponseMessage> PostAsJsonAsync<TValue>(this IHttpClient client, Uri? requestUri, TValue value, CancellationToken cancellationToken)
|
public static Task<HttpResponseMessage> PostAsJsonAsync<TValue>(
|
||||||
|
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<HttpResponseMessage> PostAsJsonAsync<TValue>(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, JsonTypeInfo<TValue> jsonTypeInfo, CancellationToken cancellationToken = default)
|
public static Task<HttpResponseMessage> PostAsJsonAsync<TValue>(
|
||||||
|
this IHttpClient client,
|
||||||
|
[StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri,
|
||||||
|
TValue value,
|
||||||
|
JsonTypeInfo<TValue> jsonTypeInfo,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.PostAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken);
|
return client._Instance.PostAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<HttpResponseMessage> PostAsJsonAsync<TValue>(this IHttpClient client, Uri? requestUri, TValue value, JsonTypeInfo<TValue> jsonTypeInfo, CancellationToken cancellationToken = default)
|
public static Task<HttpResponseMessage> PostAsJsonAsync<TValue>(
|
||||||
|
this IHttpClient client,
|
||||||
|
Uri? requestUri,
|
||||||
|
TValue value,
|
||||||
|
JsonTypeInfo<TValue> jsonTypeInfo,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.PostAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken);
|
return client._Instance.PostAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetFromJsonAsync
|
#region GetFromJsonAsync
|
||||||
public static Task<object?> GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, Type type, JsonSerializerOptions? options, CancellationToken cancellationToken = default)
|
public static Task<object?> GetFromJsonAsync(
|
||||||
|
this IHttpClient client,
|
||||||
|
[StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri,
|
||||||
|
Type type,
|
||||||
|
JsonSerializerOptions? options,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.GetFromJsonAsync(requestUri, type, options, cancellationToken);
|
return client._Instance.GetFromJsonAsync(requestUri, type, options, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<object?> GetFromJsonAsync(this IHttpClient client, Uri? requestUri, Type type, JsonSerializerOptions? options, CancellationToken cancellationToken = default)
|
public static Task<object?> GetFromJsonAsync(
|
||||||
|
this IHttpClient client,
|
||||||
|
Uri? requestUri,
|
||||||
|
Type type,
|
||||||
|
JsonSerializerOptions? options,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.GetFromJsonAsync(requestUri, type, options, cancellationToken);
|
return client._Instance.GetFromJsonAsync(requestUri, type, options, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<TValue?> GetFromJsonAsync<TValue>(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default)
|
public static Task<TValue?> GetFromJsonAsync<TValue>(
|
||||||
|
this IHttpClient client,
|
||||||
|
[StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri,
|
||||||
|
JsonSerializerOptions? options,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.GetFromJsonAsync<TValue>(requestUri, options, cancellationToken);
|
return client._Instance.GetFromJsonAsync<TValue>(requestUri, options, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<TValue?> GetFromJsonAsync<TValue>(this IHttpClient client, Uri? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default)
|
public static Task<TValue?> GetFromJsonAsync<TValue>(
|
||||||
|
this IHttpClient client,
|
||||||
|
Uri? requestUri,
|
||||||
|
JsonSerializerOptions? options,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.GetFromJsonAsync<TValue>(requestUri, options, cancellationToken);
|
return client._Instance.GetFromJsonAsync<TValue>(requestUri, options, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<object?> GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, Type type, JsonSerializerContext context, CancellationToken cancellationToken = default)
|
public static Task<object?> GetFromJsonAsync(
|
||||||
|
this IHttpClient client,
|
||||||
|
[StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri,
|
||||||
|
Type type,
|
||||||
|
JsonSerializerContext context,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.GetFromJsonAsync(requestUri, type, context, cancellationToken);
|
return client._Instance.GetFromJsonAsync(requestUri, type, context, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<object?> GetFromJsonAsync(this IHttpClient client, Uri? requestUri, Type type, JsonSerializerContext context, CancellationToken cancellationToken = default)
|
public static Task<object?> GetFromJsonAsync(
|
||||||
|
this IHttpClient client,
|
||||||
|
Uri? requestUri,
|
||||||
|
Type type,
|
||||||
|
JsonSerializerContext context,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.GetFromJsonAsync(requestUri, type, context, cancellationToken);
|
return client._Instance.GetFromJsonAsync(requestUri, type, context, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<TValue?> GetFromJsonAsync<TValue>(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, JsonTypeInfo<TValue> jsonTypeInfo, CancellationToken cancellationToken = default)
|
public static Task<TValue?> GetFromJsonAsync<TValue>(
|
||||||
|
this IHttpClient client,
|
||||||
|
[StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri,
|
||||||
|
JsonTypeInfo<TValue> jsonTypeInfo,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.GetFromJsonAsync(requestUri, jsonTypeInfo, cancellationToken);
|
return client._Instance.GetFromJsonAsync(requestUri, jsonTypeInfo, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<TValue?> GetFromJsonAsync<TValue>(this IHttpClient client, Uri? requestUri, JsonTypeInfo<TValue> jsonTypeInfo, CancellationToken cancellationToken = default)
|
public static Task<TValue?> GetFromJsonAsync<TValue>(
|
||||||
|
this IHttpClient client,
|
||||||
|
Uri? requestUri,
|
||||||
|
JsonTypeInfo<TValue> jsonTypeInfo,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.GetFromJsonAsync(requestUri, jsonTypeInfo, cancellationToken);
|
return client._Instance.GetFromJsonAsync(requestUri, jsonTypeInfo, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<object?> GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, Type type, CancellationToken cancellationToken = default)
|
public static Task<object?> 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<object?> GetFromJsonAsync(this IHttpClient client, Uri? requestUri, Type type, CancellationToken cancellationToken = default)
|
public static Task<object?> 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<TValue?> GetFromJsonAsync<TValue>(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, CancellationToken cancellationToken = default)
|
public static Task<TValue?> GetFromJsonAsync<TValue>(
|
||||||
|
this IHttpClient client,
|
||||||
|
[StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.GetFromJsonAsync<TValue>(requestUri, cancellationToken);
|
return client._Instance.GetFromJsonAsync<TValue>(requestUri, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<TValue?> GetFromJsonAsync<TValue>(this IHttpClient client, Uri? requestUri, CancellationToken cancellationToken = default)
|
public static Task<TValue?> GetFromJsonAsync<TValue>(
|
||||||
|
this IHttpClient client,
|
||||||
|
Uri? requestUri,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client._Instance.GetFromJsonAsync<TValue>(requestUri, cancellationToken);
|
return client._Instance.GetFromJsonAsync<TValue>(requestUri, cancellationToken);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ using ProxyInterfaceGenerator;
|
|||||||
|
|
||||||
namespace ProxyInterfaceConsumer
|
namespace ProxyInterfaceConsumer
|
||||||
{
|
{
|
||||||
[Proxy(typeof(Address), false, ProxyClassAccessibility.Public, new []{"Weird"})]
|
[Proxy(typeof(Address), false, ProxyClassAccessibility.Public, new[] { "Weird" })]
|
||||||
public partial interface IAddress
|
public partial interface IAddress
|
||||||
{
|
{
|
||||||
public void Weird()
|
public void Weird()
|
||||||
@@ -10,4 +10,4 @@ namespace ProxyInterfaceConsumer
|
|||||||
_Instance.Weird2();
|
_Instance.Weird2();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
namespace ProxyInterfaceConsumer
|
namespace ProxyInterfaceConsumer
|
||||||
{
|
{
|
||||||
// [ProxyInterfaceGenerator.Proxy(typeof(Microsoft.CodeAnalysis.GeneratorExecutionContext))]
|
// [ProxyInterfaceGenerator.Proxy(typeof(Microsoft.CodeAnalysis.GeneratorExecutionContext))]
|
||||||
public partial interface IGeneratorExecutionContext
|
public partial interface IGeneratorExecutionContext { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceConsumer
|
namespace ProxyInterfaceConsumer
|
||||||
{
|
{
|
||||||
public interface IMyInterface
|
public interface IMyInterface { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,7 +3,5 @@ using ProxyInterfaceGenerator;
|
|||||||
namespace ProxyInterfaceConsumer
|
namespace ProxyInterfaceConsumer
|
||||||
{
|
{
|
||||||
[Proxy(typeof(ProxyInterfaceConsumer.Person), ProxyClassAccessibility.Internal)]
|
[Proxy(typeof(ProxyInterfaceConsumer.Person), ProxyClassAccessibility.Internal)]
|
||||||
public partial interface IPerson
|
public partial interface IPerson { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,6 +2,5 @@ namespace ProxyInterfaceConsumer
|
|||||||
{
|
{
|
||||||
[ProxyInterfaceGenerator.Proxy(typeof(ProxyInterfaceConsumer.PersonT<>))]
|
[ProxyInterfaceGenerator.Proxy(typeof(ProxyInterfaceConsumer.PersonT<>))]
|
||||||
public partial interface IPersonT //<T> where T : struct
|
public partial interface IPersonT //<T> where T : struct
|
||||||
{
|
{ }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
namespace ProxyInterfaceConsumer
|
namespace ProxyInterfaceConsumer
|
||||||
{
|
{
|
||||||
[ProxyInterfaceGenerator.Proxy(typeof(ProxyInterfaceConsumer.PersonTT<,>))]
|
[ProxyInterfaceGenerator.Proxy(typeof(ProxyInterfaceConsumer.PersonTT<,>))]
|
||||||
public partial interface IPersonTT<T1, T2>
|
public partial interface IPersonTT<T1, T2>
|
||||||
where T1 : struct
|
where T1 : struct
|
||||||
where T2 : class, new()
|
where T2 : class, new() { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -10,28 +10,30 @@ namespace ProxyInterfaceConsumer
|
|||||||
public int Id { get; }
|
public int Id { get; }
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
||||||
public object @object { get; set; }= null!;
|
public object @object { get; set; } = null!;
|
||||||
|
|
||||||
public long? NullableLong { get; }
|
public long? NullableLong { get; }
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
||||||
public string Name { get; set; }= null!;
|
public string Name { get; set; } = null!;
|
||||||
|
|
||||||
public string? StringNullable { get; set; }
|
public string? StringNullable { get; set; }
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
||||||
public Address Address { get; set; }= null!;
|
public Address Address { get; set; } = null!;
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
||||||
public List<Address> AddressesList { get; set; }= null!;
|
public List<Address> AddressesList { get; set; } = null!;
|
||||||
|
|
||||||
public Dictionary<string, Address> AddressesDict { get; set; } = new Dictionary<string, Address>();
|
public Dictionary<string, Address> AddressesDict { get; set; } =
|
||||||
public Dictionary<Address, Address> AddressesDict2 { get; set; } = new Dictionary<Address, Address>();
|
new Dictionary<string, Address>();
|
||||||
|
public Dictionary<Address, Address> AddressesDict2 { get; set; } =
|
||||||
|
new Dictionary<Address, Address>();
|
||||||
|
|
||||||
public E E { get; set; }
|
public E E { get; set; }
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
||||||
public IMyInterface MyInterface { get; set; }= null!;
|
public IMyInterface MyInterface { get; set; } = null!;
|
||||||
|
|
||||||
public bool TMethod<T1, T2>(int x, T1 t1, T2 t2)
|
public bool TMethod<T1, T2>(int x, T1 t1, T2 t2)
|
||||||
where T1 : struct
|
where T1 : struct
|
||||||
@@ -55,9 +57,7 @@ namespace ProxyInterfaceConsumer
|
|||||||
return $"Hello {name} !";
|
return $"Hello {name} !";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddWithParams(params string[] values)
|
public void AddWithParams(params string[] values) { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Address AddAddress(Address a)
|
public Address AddAddress(Address a)
|
||||||
{
|
{
|
||||||
@@ -66,9 +66,7 @@ namespace ProxyInterfaceConsumer
|
|||||||
return a;
|
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)
|
public void In_Out_Ref1(in int a, out int b, ref int c)
|
||||||
{
|
{
|
||||||
@@ -83,9 +81,7 @@ namespace ProxyInterfaceConsumer
|
|||||||
// return 404;
|
// return 404;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
public void Void()
|
public void Void() { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Method1Async()
|
public Task Method1Async()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
namespace ProxyInterfaceConsumer
|
namespace ProxyInterfaceConsumer
|
||||||
{
|
{
|
||||||
public class PersonT<T> where T : struct
|
public class PersonT<T>
|
||||||
|
where T : struct
|
||||||
{
|
{
|
||||||
public T TVal { get; set; }
|
public T TVal { get; set; }
|
||||||
|
|
||||||
@@ -14,4 +15,4 @@ namespace ProxyInterfaceConsumer
|
|||||||
return new PersonT<T>();
|
return new PersonT<T>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ namespace ProxyInterfaceConsumer
|
|||||||
|
|
||||||
public T2 TVal2 { get; set; }
|
public T2 TVal2 { get; set; }
|
||||||
|
|
||||||
public void Call(int x, T1 t1, T2 t2)
|
public void Call(int x, T1 t1, T2 t2) { }
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ namespace ProxyInterfaceConsumer;
|
|||||||
|
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
private static JsonSerializerOptions JsonSerializerOptions = new ()
|
private static JsonSerializerOptions JsonSerializerOptions = new() { WriteIndented = true };
|
||||||
{
|
|
||||||
WriteIndented = true
|
|
||||||
};
|
|
||||||
|
|
||||||
public static async Task Main()
|
public static async Task Main()
|
||||||
{
|
{
|
||||||
@@ -24,7 +21,10 @@ public class Program
|
|||||||
var result = await ph.GetAsync("https://www.google.nl");
|
var result = await ph.GetAsync("https://www.google.nl");
|
||||||
var todo = await ph.GetFromJsonAsync<Todo>("https://jsonplaceholder.typicode.com/todos/1");
|
var todo = await ph.GetFromJsonAsync<Todo>("https://jsonplaceholder.typicode.com/todos/1");
|
||||||
|
|
||||||
var postResult = await h.PostAsJsonAsync<Todo>("https://jsonplaceholder.typicode.com/todos", new Todo { Id = 123 });
|
var postResult = await h.PostAsJsonAsync<Todo>(
|
||||||
|
"https://jsonplaceholder.typicode.com/todos",
|
||||||
|
new Todo { Id = 123 }
|
||||||
|
);
|
||||||
|
|
||||||
var t = new TestProxy(new Test());
|
var t = new TestProxy(new Test());
|
||||||
|
|
||||||
@@ -41,9 +41,7 @@ public class Program
|
|||||||
|
|
||||||
var ap = new AddressProxy(new Address { HouseNumber = 42 });
|
var ap = new AddressProxy(new Address { HouseNumber = 42 });
|
||||||
ap.HouseNumber = -1;
|
ap.HouseNumber = -1;
|
||||||
ap.MyEvent += delegate (object x, EventArgs a)
|
ap.MyEvent += delegate(object x, EventArgs a) { };
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
IPerson p = new PersonProxy(new Person());
|
IPerson p = new PersonProxy(new Person());
|
||||||
p.Name = "test";
|
p.Name = "test";
|
||||||
@@ -93,11 +91,7 @@ public sealed class Clazz
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProxyInterfaceGenerator.Proxy(typeof(Test))]
|
[ProxyInterfaceGenerator.Proxy(typeof(Test))]
|
||||||
public partial interface ITest
|
public partial interface ITest { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[ProxyInterfaceGenerator.Proxy(typeof(Clazz))]
|
[ProxyInterfaceGenerator.Proxy(typeof(Clazz))]
|
||||||
public partial interface IClazz
|
public partial interface IClazz { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,6 +4,4 @@ using Akka.Remote;
|
|||||||
|
|
||||||
[ProxyInterfaceGenerator.Proxy(typeof(AddressUid))]
|
[ProxyInterfaceGenerator.Proxy(typeof(AddressUid))]
|
||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
public partial interface IAddressUid
|
public partial interface IAddressUid { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,7 +3,5 @@ using Akka.Actor;
|
|||||||
namespace ProxyInterfaceConsumerForAkka.Interfaces
|
namespace ProxyInterfaceConsumerForAkka.Interfaces
|
||||||
{
|
{
|
||||||
[ProxyInterfaceGenerator.Proxy(typeof(LocalActorRefProvider))]
|
[ProxyInterfaceGenerator.Proxy(typeof(LocalActorRefProvider))]
|
||||||
public partial interface ILocalActorRefProvider
|
public partial interface ILocalActorRefProvider { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,9 +11,15 @@ namespace ProxyInterfaceConsumerForPnP.Interfaces;
|
|||||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||||
public partial class ClientContextProxy
|
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<ClientRuntimeContext>(clientContext);
|
ClientRuntimeContext clientObject_ = Mapster.TypeAdapter.Adapt<ClientRuntimeContext>(
|
||||||
|
clientContext
|
||||||
|
);
|
||||||
return clientObject_.ExecuteQueryRetryAsync(retryCount, userAgent);
|
return clientObject_.ExecuteQueryRetryAsync(retryCount, userAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,17 +31,24 @@ public partial class ClientContextProxy
|
|||||||
_Instance.Load<T>(clientObject_, retrievals_);
|
_Instance.Load<T>(clientObject_, retrievals_);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Load<TSource, TTarget>(Interfaces.IClientObject clientObject, params Expression<Func<TSource, object>>[] retrievals)
|
public void Load<TSource, TTarget>(
|
||||||
|
Interfaces.IClientObject clientObject,
|
||||||
|
params Expression<Func<TSource, object>>[] retrievals
|
||||||
|
)
|
||||||
where TSource : Interfaces.IClientObject
|
where TSource : Interfaces.IClientObject
|
||||||
where TTarget : ClientObject
|
where TTarget : ClientObject
|
||||||
{
|
{
|
||||||
TTarget clientObject_ = Mapster.TypeAdapter.Adapt<TTarget>(clientObject);
|
TTarget clientObject_ = Mapster.TypeAdapter.Adapt<TTarget>(clientObject);
|
||||||
Expression<Func<TTarget, object>>[] retrievals_ = retrievals.Select(MapExpression<TSource, TTarget>).ToArray();
|
Expression<Func<TTarget, object>>[] retrievals_ = retrievals
|
||||||
|
.Select(MapExpression<TSource, TTarget>)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
_Instance.Load(clientObject_, retrievals_);
|
_Instance.Load(clientObject_, retrievals_);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Expression<Func<TTarget, object>> MapExpression<TSource, TTarget>(Expression<Func<TSource, object>> expression)
|
private static Expression<Func<TTarget, object>> MapExpression<TSource, TTarget>(
|
||||||
|
Expression<Func<TSource, object>> expression
|
||||||
|
)
|
||||||
where TSource : Interfaces.IClientObject
|
where TSource : Interfaces.IClientObject
|
||||||
where TTarget : ClientObject
|
where TTarget : ClientObject
|
||||||
{
|
{
|
||||||
@@ -45,20 +58,28 @@ public partial class ClientContextProxy
|
|||||||
switch (expression.Body)
|
switch (expression.Body)
|
||||||
{
|
{
|
||||||
case MemberExpression memberExpression:
|
case MemberExpression memberExpression:
|
||||||
memberAccessExpression = Expression.PropertyOrField(parameterExpression, memberExpression.Member.Name);
|
memberAccessExpression = Expression.PropertyOrField(
|
||||||
|
parameterExpression,
|
||||||
|
memberExpression.Member.Name
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UnaryExpression unaryExpression:
|
case UnaryExpression unaryExpression:
|
||||||
var expressionOperand = (MemberExpression)unaryExpression.Operand;
|
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));
|
memberAccessExpression = Expression.Convert(memberAccessExpression, typeof(object));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Expression.Lambda<Func<TTarget, object>>(memberAccessExpression, parameterExpression);
|
return Expression.Lambda<Func<TTarget, object>>(
|
||||||
|
memberAccessExpression,
|
||||||
|
parameterExpression
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-3
@@ -6,9 +6,15 @@ namespace ProxyInterfaceConsumerForPnP.Implementations;
|
|||||||
|
|
||||||
public static class ClientRuntimeContextExtensions
|
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<ClientRuntimeContext>(clientContext);
|
ClientRuntimeContext clientObject_ = Mapster.TypeAdapter.Adapt<ClientRuntimeContext>(
|
||||||
|
clientContext
|
||||||
|
);
|
||||||
return clientObject_.ExecuteQueryRetryAsync(retryCount, userAgent);
|
return clientObject_.ExecuteQueryRetryAsync(retryCount, userAgent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,11 @@ namespace ProxyInterfaceConsumerForPnP.Interfaces
|
|||||||
[ProxyInterfaceGenerator.Proxy(typeof(ClientContext))]
|
[ProxyInterfaceGenerator.Proxy(typeof(ClientContext))]
|
||||||
public partial interface IClientContext : IClientRuntimeContext
|
public partial interface IClientContext : IClientRuntimeContext
|
||||||
{
|
{
|
||||||
void Load<TSource, TTarget>(IClientObject clientObject, params Expression<Func<TSource, object>>[] retrievals)
|
void Load<TSource, TTarget>(
|
||||||
|
IClientObject clientObject,
|
||||||
|
params Expression<Func<TSource, object>>[] retrievals
|
||||||
|
)
|
||||||
where TSource : IClientObject
|
where TSource : IClientObject
|
||||||
where TTarget : ClientObject;
|
where TTarget : ClientObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
namespace ProxyInterfaceConsumerForPnP.Interfaces
|
namespace ProxyInterfaceConsumerForPnP.Interfaces
|
||||||
{
|
{
|
||||||
[ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.ClientObject))]
|
[ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.ClientObject))]
|
||||||
public partial interface IClientObject
|
public partial interface IClientObject { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
namespace ProxyInterfaceConsumerForPnP.Interfaces
|
namespace ProxyInterfaceConsumerForPnP.Interfaces
|
||||||
{
|
{
|
||||||
[ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.ClientRuntimeContext))]
|
[ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.ClientRuntimeContext))]
|
||||||
public partial interface IClientRuntimeContext
|
public partial interface IClientRuntimeContext { }
|
||||||
{
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,4 +7,4 @@
|
|||||||
// public partial interface IProxyListCollection: IClientObject, IEnumerable, IQueryable
|
// public partial interface IProxyListCollection: IClientObject, IEnumerable, IQueryable
|
||||||
// {
|
// {
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ namespace ProxyInterfaceConsumerForPnP.Interfaces
|
|||||||
{
|
{
|
||||||
// public virtual void X();
|
// public virtual void X();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
namespace ProxyInterfaceConsumerForPnP.Interfaces
|
namespace ProxyInterfaceConsumerForPnP.Interfaces
|
||||||
{
|
{
|
||||||
[ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.User))]
|
[ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.User))]
|
||||||
public partial interface IUser
|
public partial interface IUser { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
namespace ProxyInterfaceConsumerForPnP.Interfaces
|
namespace ProxyInterfaceConsumerForPnP.Interfaces
|
||||||
{
|
{
|
||||||
[ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.Web))]
|
[ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.Web))]
|
||||||
public partial interface IWeb: ISecurableObject
|
public partial interface IWeb : ISecurableObject { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -18,9 +18,12 @@ public class Program
|
|||||||
"15b347bf-90a2-4c16-aa76-5a3263476b59",
|
"15b347bf-90a2-4c16-aa76-5a3263476b59",
|
||||||
"Test.pfx",
|
"Test.pfx",
|
||||||
Environment.GetEnvironmentVariable("Test.pfx_PWD"),
|
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);
|
clientContext.Load(clientContext.Web, p => p.Title);
|
||||||
await clientContext.ExecuteQueryRetryAsync();
|
await clientContext.ExecuteQueryRetryAsync();
|
||||||
|
|
||||||
@@ -28,7 +31,12 @@ public class Program
|
|||||||
|
|
||||||
IClientContext cp = new ClientContextProxy(clientContext);
|
IClientContext cp = new ClientContextProxy(clientContext);
|
||||||
|
|
||||||
cp.Load<ProxyInterfaceConsumerForPnP.Interfaces.IWeb, Web>(cp.Web, w => w.Lists, w => w.Language, w => w.Author);
|
cp.Load<ProxyInterfaceConsumerForPnP.Interfaces.IWeb, Web>(
|
||||||
|
cp.Web,
|
||||||
|
w => w.Lists,
|
||||||
|
w => w.Language,
|
||||||
|
w => w.Author
|
||||||
|
);
|
||||||
|
|
||||||
await cp.ExecuteQueryRetryAsync();
|
await cp.ExecuteQueryRetryAsync();
|
||||||
|
|
||||||
@@ -55,4 +63,4 @@ public class Program
|
|||||||
Console.WriteLine("Error Message: " + ex.Message);
|
Console.WriteLine("Error Message: " + ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,4 +4,4 @@
|
|||||||
{
|
{
|
||||||
public int HouseNumber { get; set; }
|
public int HouseNumber { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
namespace ProxyInterfaceConsumer
|
namespace ProxyInterfaceConsumer
|
||||||
{
|
{
|
||||||
[ProxyInterfaceGenerator.Proxy(typeof(ProxyInterfaceConsumer.Address))]
|
[ProxyInterfaceGenerator.Proxy(typeof(ProxyInterfaceConsumer.Address))]
|
||||||
public partial interface IAddress
|
public partial interface IAddress { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceConsumer
|
namespace ProxyInterfaceConsumer
|
||||||
{
|
{
|
||||||
public interface IMyInterface
|
public interface IMyInterface { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,7 +3,5 @@ using ProxyInterfaceGenerator;
|
|||||||
namespace ProxyInterfaceConsumer
|
namespace ProxyInterfaceConsumer
|
||||||
{
|
{
|
||||||
[Proxy(typeof(Person), ProxyClassAccessibility.Internal)]
|
[Proxy(typeof(Person), ProxyClassAccessibility.Internal)]
|
||||||
public partial interface IPerson
|
public partial interface IPerson { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -10,37 +10,37 @@ namespace ProxyInterfaceConsumer
|
|||||||
public int Id { get; }
|
public int Id { get; }
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
||||||
public object @object { get; set; }= null!;
|
public object @object { get; set; } = null!;
|
||||||
|
|
||||||
public long? NullableLong { get; }
|
public long? NullableLong { get; }
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
||||||
public string Name { get; set; }= null!;
|
public string Name { get; set; } = null!;
|
||||||
|
|
||||||
public string? StringNullable { get; set; }
|
public string? StringNullable { get; set; }
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
||||||
public Address Address { get; set; }= null!;
|
public Address Address { get; set; } = null!;
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
||||||
public List<Address> AddressesLIst { get; set; }= null!;
|
public List<Address> AddressesLIst { get; set; } = null!;
|
||||||
|
|
||||||
public Dictionary<string, Address> AddressesDict { get; set; } = new Dictionary<string, Address>();
|
public Dictionary<string, Address> AddressesDict { get; set; } =
|
||||||
public Dictionary<Address, Address> AddressesDict2 { get; set; } = new Dictionary<Address, Address>();
|
new Dictionary<string, Address>();
|
||||||
|
public Dictionary<Address, Address> AddressesDict2 { get; set; } =
|
||||||
|
new Dictionary<Address, Address>();
|
||||||
|
|
||||||
public E E { get; set; }
|
public E E { get; set; }
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
||||||
public IMyInterface MyInterface { get; set; }= null!;
|
public IMyInterface MyInterface { get; set; } = null!;
|
||||||
|
|
||||||
public string Add(string s, string @string)
|
public string Add(string s, string @string)
|
||||||
{
|
{
|
||||||
return s + @string;
|
return s + @string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddWithParams(params string[] values)
|
public void AddWithParams(params string[] values) { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Address AddAddress(Address a)
|
public Address AddAddress(Address a)
|
||||||
{
|
{
|
||||||
@@ -49,9 +49,7 @@ namespace ProxyInterfaceConsumer
|
|||||||
return a;
|
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)
|
public void In_Out_Ref1(in int a, out int b, ref int c)
|
||||||
{
|
{
|
||||||
@@ -64,9 +62,7 @@ namespace ProxyInterfaceConsumer
|
|||||||
return 404;
|
return 404;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Void()
|
public void Void() { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Method1Async()
|
public Task Method1Async()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ namespace ProxyInterfaceConsumer
|
|||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
private static JsonSerializerOptions JsonSerializerOptions = new ()
|
private static JsonSerializerOptions JsonSerializerOptions = new() { WriteIndented = true };
|
||||||
{
|
|
||||||
WriteIndented = true
|
|
||||||
};
|
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
@@ -24,4 +21,4 @@ namespace ProxyInterfaceConsumer
|
|||||||
Console.WriteLine(JsonSerializer.Serialize(p, JsonSerializerOptions));
|
Console.WriteLine(JsonSerializer.Serialize(p, JsonSerializerOptions));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ internal static class MethodParameterBuilder
|
|||||||
stringBuilder.Append(parameterSymbol.GetRefKindPrefix()); // "" or "out "
|
stringBuilder.Append(parameterSymbol.GetRefKindPrefix()); // "" or "out "
|
||||||
stringBuilder.AppendFormat("{0} ", type); // string or another type
|
stringBuilder.AppendFormat("{0} ", type); // string or another type
|
||||||
}
|
}
|
||||||
|
|
||||||
stringBuilder.Append(parameterSymbol.GetSanitizedName()); // "s" or "i" or ...
|
stringBuilder.Append(parameterSymbol.GetSanitizedName()); // "s" or "i" or ...
|
||||||
stringBuilder.Append(parameterSymbol.GetDefaultValue()); // "" or the value
|
stringBuilder.Append(parameterSymbol.GetDefaultValue()); // "" or the value
|
||||||
|
|
||||||
return stringBuilder.ToString();
|
return stringBuilder.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ internal enum TypeEnum
|
|||||||
Interface,
|
Interface,
|
||||||
|
|
||||||
Complex
|
Complex
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ namespace Speckle.ProxyGenerator.Extensions;
|
|||||||
internal static class MethodSymbolExtensions
|
internal static class MethodSymbolExtensions
|
||||||
{
|
{
|
||||||
public static string GetMethodNameWithOptionalTypeParameters(this IMethodSymbol method) =>
|
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) =>
|
//public static string GetWhereStatement(this IMethodSymbol method) =>
|
||||||
// !method.IsGenericMethod ? string.Empty : string.Join("", method.TypeParameters.Select(tp => tp.GetWhereConstraints()));
|
// !method.IsGenericMethod ? string.Empty : string.Join("", method.TypeParameters.Select(tp => tp.GetWhereConstraints()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,22 +41,34 @@ internal static class NamedTypeSymbolExtensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static string ResolveProxyClassName(this INamedTypeSymbol namedTypeSymbol)
|
public static string ResolveProxyClassName(this INamedTypeSymbol namedTypeSymbol)
|
||||||
{
|
{
|
||||||
return !namedTypeSymbol.IsGenericType ?
|
return !namedTypeSymbol.IsGenericType
|
||||||
$"{namedTypeSymbol.Name}Proxy" :
|
? $"{namedTypeSymbol.Name}Proxy"
|
||||||
$"{namedTypeSymbol.Name}Proxy<{string.Join(", ", namedTypeSymbol.TypeArguments.Select(ta => ta.Name))}>";
|
: $"{namedTypeSymbol.Name}Proxy<{string.Join(", ", namedTypeSymbol.TypeArguments.Select(ta => ta.Name))}>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<INamedTypeSymbol> ResolveImplementedInterfaces(this INamedTypeSymbol symbol, bool proxyBaseClasses)
|
public static List<INamedTypeSymbol> ResolveImplementedInterfaces(
|
||||||
|
this INamedTypeSymbol symbol,
|
||||||
|
bool proxyBaseClasses
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// Members implemented by us or base classes should go here.
|
// 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.
|
// Direct interfaces, recursive interfaces or base class interfaces should go here.
|
||||||
var interfaces = new List<INamedTypeSymbol>(symbol.Interfaces);
|
var interfaces = new List<INamedTypeSymbol>(symbol.Interfaces);
|
||||||
var baseType = symbol.BaseType;
|
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);
|
interfaces.AddRange(baseType.Interfaces);
|
||||||
baseType = baseType.BaseType;
|
baseType = baseType.BaseType;
|
||||||
}
|
}
|
||||||
@@ -66,7 +78,10 @@ internal static class NamedTypeSymbolExtensions
|
|||||||
foreach (var @interface in interfaces)
|
foreach (var @interface in interfaces)
|
||||||
{
|
{
|
||||||
var isRealized = true;
|
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)
|
foreach (var member in allMembers)
|
||||||
{
|
{
|
||||||
var implementation = symbol.FindImplementationForInterfaceMember(member);
|
var implementation = symbol.FindImplementationForInterfaceMember(member);
|
||||||
@@ -85,4 +100,4 @@ internal static class NamedTypeSymbolExtensions
|
|||||||
|
|
||||||
return realizedInterfaces;
|
return realizedInterfaces;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
public static string GetDefaultValue(this IParameterSymbol ps)
|
||||||
{
|
{
|
||||||
@@ -44,7 +45,8 @@ internal static class ParameterSymbolExtensions
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
defaultValue = ps.Type.IsReferenceType
|
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)".
|
$"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();
|
public static TypeEnum GetTypeEnum(this IParameterSymbol p) => p.Type.GetTypeEnum();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ internal static class PropertySymbolExtensions
|
|||||||
{
|
{
|
||||||
public static TypeEnum GetTypeEnum(this IPropertySymbol p) => p.Type.GetTypeEnum();
|
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 getIsPublic = property.GetMethod.IsPublic();
|
||||||
var setIsPublic = property.SetMethod.IsPublic();
|
var setIsPublic = property.SetMethod.IsPublic();
|
||||||
@@ -21,9 +24,13 @@ internal static class PropertySymbolExtensions
|
|||||||
var get = getIsPublic ? "get; " : string.Empty;
|
var get = getIsPublic ? "get; " : string.Empty;
|
||||||
var set = setIsPublic ? "set; " : string.Empty;
|
var set = setIsPublic ? "set; " : string.Empty;
|
||||||
|
|
||||||
var type = !string.IsNullOrEmpty(overrideType) ? overrideType
|
var type = !string.IsNullOrEmpty(overrideType)
|
||||||
: BaseGenerator.FixType(property.Type.ToFullyQualifiedDisplayString(), property.NullableAnnotation);
|
? overrideType
|
||||||
|
: BaseGenerator.FixType(
|
||||||
|
property.Type.ToFullyQualifiedDisplayString(),
|
||||||
|
property.NullableAnnotation
|
||||||
|
);
|
||||||
|
|
||||||
return (type!, property.GetSanitizedName(), $"{{ {get}{set}}}");
|
return (type!, property.GetSanitizedName(), $"{{ {get}{set}}}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,4 +38,4 @@ internal static class StringExtensions
|
|||||||
{
|
{
|
||||||
return fullTypeName.Split('.').LastOrDefault() ?? fullTypeName;
|
return fullTypeName.Split('.').LastOrDefault() ?? fullTypeName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,13 @@ internal static class SymbolExtensions
|
|||||||
{
|
{
|
||||||
return symbol
|
return symbol
|
||||||
.GetAttributes()
|
.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}]")
|
.Select(a => $"[{a}]")
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
@@ -53,7 +59,10 @@ internal static class SymbolExtensions
|
|||||||
sb.Insert(0, '.');
|
sb.Insert(0, '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Insert(0, s.OriginalDefinition.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat));
|
sb.Insert(
|
||||||
|
0,
|
||||||
|
s.OriginalDefinition.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat)
|
||||||
|
);
|
||||||
s = s.ContainingSymbol;
|
s = s.ContainingSymbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,11 +73,12 @@ internal static class SymbolExtensions
|
|||||||
symbol.IsKeywordOrReserved() ? $"@{symbol.Name}" : symbol.Name;
|
symbol.IsKeywordOrReserved() ? $"@{symbol.Name}" : symbol.Name;
|
||||||
|
|
||||||
public static bool IsKeywordOrReserved(this ISymbol symbol) =>
|
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) =>
|
public static bool IsPublic(this ISymbol? symbol) =>
|
||||||
symbol is { DeclaredAccessibility: Accessibility.Public };
|
symbol is { DeclaredAccessibility: Accessibility.Public };
|
||||||
|
|
||||||
private static bool IsRootNamespace(ISymbol symbol) =>
|
private static bool IsRootNamespace(ISymbol symbol) =>
|
||||||
symbol is INamespaceSymbol { IsGlobalNamespace: true };
|
symbol is INamespaceSymbol { IsGlobalNamespace: true };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ namespace Speckle.ProxyGenerator.Extensions;
|
|||||||
internal static class SyntaxNodeExtensions
|
internal static class SyntaxNodeExtensions
|
||||||
{
|
{
|
||||||
// https://stackoverflow.com/questions/20458457/getting-class-fullname-including-namespace-from-roslyn-classdeclarationsyntax
|
// https://stackoverflow.com/questions/20458457/getting-class-fullname-including-namespace-from-roslyn-classdeclarationsyntax
|
||||||
public static bool TryGetParentSyntax<T>(this SyntaxNode? syntaxNode, [NotNullWhen(true)] out T? result) where T : SyntaxNode
|
public static bool TryGetParentSyntax<T>(
|
||||||
|
this SyntaxNode? syntaxNode,
|
||||||
|
[NotNullWhen(true)] out T? result
|
||||||
|
)
|
||||||
|
where T : SyntaxNode
|
||||||
{
|
{
|
||||||
result = null;
|
result = null;
|
||||||
|
|
||||||
@@ -57,9 +61,11 @@ internal static class SyntaxNodeExtensions
|
|||||||
|
|
||||||
// Keep moving "out" of nested classes etc until we get to a namespace
|
// Keep moving "out" of nested classes etc until we get to a namespace
|
||||||
// or until we run out of parents
|
// or until we run out of parents
|
||||||
while (potentialNamespaceParent != null &&
|
while (
|
||||||
potentialNamespaceParent is not NamespaceDeclarationSyntax
|
potentialNamespaceParent != null
|
||||||
&& potentialNamespaceParent is not FileScopedNamespaceDeclarationSyntax)
|
&& potentialNamespaceParent is not NamespaceDeclarationSyntax
|
||||||
|
&& potentialNamespaceParent is not FileScopedNamespaceDeclarationSyntax
|
||||||
|
)
|
||||||
{
|
{
|
||||||
potentialNamespaceParent = potentialNamespaceParent.Parent;
|
potentialNamespaceParent = potentialNamespaceParent.Parent;
|
||||||
}
|
}
|
||||||
@@ -88,4 +94,4 @@ internal static class SyntaxNodeExtensions
|
|||||||
// return the final namespace
|
// return the final namespace
|
||||||
return nameSpace;
|
return nameSpace;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ internal static class TypeSymbolExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsString(this ITypeSymbol ts) =>
|
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) =>
|
public static string ToFullyQualifiedDisplayString(this ITypeSymbol property) =>
|
||||||
property.ToDisplayString(NullableFlowState.None, SymbolDisplayFormat.FullyQualifiedFormat);
|
property.ToDisplayString(NullableFlowState.None, SymbolDisplayFormat.FullyQualifiedFormat);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,10 @@ internal abstract class BaseGenerator
|
|||||||
return GetReplacedTypeAsString(property.Type, out isReplaced);
|
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);
|
proxyData = Context.Candidates.Values.FirstOrDefault(x => x.FullQualifiedTypeName == type);
|
||||||
return proxyData != null;
|
return proxyData != null;
|
||||||
@@ -55,16 +58,23 @@ internal abstract class BaseGenerator
|
|||||||
return string.Concat(list);
|
return string.Concat(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected string ResolveInterfaceNameWithOptionalTypeConstraints(INamedTypeSymbol namedTypeSymbol, string interfaceName)
|
protected string ResolveInterfaceNameWithOptionalTypeConstraints(
|
||||||
|
INamedTypeSymbol namedTypeSymbol,
|
||||||
|
string interfaceName
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (!namedTypeSymbol.IsGenericType)
|
if (!namedTypeSymbol.IsGenericType)
|
||||||
{
|
{
|
||||||
return interfaceName;
|
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<ITypeParameterSymbol>())
|
foreach (
|
||||||
|
var typeParameterSymbol in namedTypeSymbol.TypeArguments.OfType<ITypeParameterSymbol>()
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (TryGetWhereConstraints(typeParameterSymbol, false, out var constraint))
|
if (TryGetWhereConstraints(typeParameterSymbol, false, out var constraint))
|
||||||
{
|
{
|
||||||
@@ -78,7 +88,11 @@ internal abstract class BaseGenerator
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// https://www.codeproject.com/Articles/871704/Roslyn-Code-Analysis-in-Easy-Samples-Part-2
|
/// https://www.codeproject.com/Articles/871704/Roslyn-Code-Analysis-in-Easy-Samples-Part-2
|
||||||
/// </summary>
|
/// </summary>
|
||||||
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<string>();
|
var constraints = new List<string>();
|
||||||
if (typeParameterSymbol.HasReferenceTypeConstraint)
|
if (typeParameterSymbol.HasReferenceTypeConstraint)
|
||||||
@@ -91,7 +105,9 @@ internal abstract class BaseGenerator
|
|||||||
constraints.Add("struct");
|
constraints.Add("struct");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var namedTypeSymbol in typeParameterSymbol.ConstraintTypes.OfType<INamedTypeSymbol>())
|
foreach (
|
||||||
|
var namedTypeSymbol in typeParameterSymbol.ConstraintTypes.OfType<INamedTypeSymbol>()
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (replaceIt)
|
if (replaceIt)
|
||||||
{
|
{
|
||||||
@@ -120,20 +136,23 @@ internal abstract class BaseGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal readonly SymbolDisplayFormat NullableDisplayFormat = new SymbolDisplayFormat(
|
internal readonly SymbolDisplayFormat NullableDisplayFormat = new SymbolDisplayFormat(
|
||||||
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included,
|
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included,
|
||||||
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
|
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
|
||||||
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
|
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
|
||||||
miscellaneousOptions:
|
miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers
|
||||||
SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers |
|
| SymbolDisplayMiscellaneousOptions.UseSpecialTypes
|
||||||
SymbolDisplayMiscellaneousOptions.UseSpecialTypes |
|
| SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier
|
||||||
SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier);
|
);
|
||||||
|
|
||||||
protected string GetReplacedTypeAsString(ITypeSymbol typeSymbol, out bool isReplaced)
|
protected string GetReplacedTypeAsString(ITypeSymbol typeSymbol, out bool isReplaced)
|
||||||
{
|
{
|
||||||
isReplaced = false;
|
isReplaced = false;
|
||||||
|
|
||||||
var typeSymbolAsString = typeSymbol.ToFullyQualifiedDisplayString();
|
var typeSymbolAsString = typeSymbol.ToFullyQualifiedDisplayString();
|
||||||
var nullableTypeSymbolAsString = typeSymbol.ToDisplayString(NullableFlowState.None, NullableDisplayFormat);
|
var nullableTypeSymbolAsString = typeSymbol.ToDisplayString(
|
||||||
|
NullableFlowState.None,
|
||||||
|
NullableDisplayFormat
|
||||||
|
);
|
||||||
|
|
||||||
if (TryFindProxyDataByTypeName(typeSymbolAsString, out var existing))
|
if (TryFindProxyDataByTypeName(typeSymbolAsString, out var existing))
|
||||||
{
|
{
|
||||||
@@ -171,17 +190,28 @@ internal abstract class BaseGenerator
|
|||||||
|
|
||||||
if (!Context.ReplacedTypes.ContainsKey(typeArgumentAsString))
|
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);
|
return FixType(propertyTypeAsStringToBeModified, typeSymbol.NullableAnnotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool TryGetNamedTypeSymbolByFullName(TypeKind kind, string name, IEnumerable<string> usings, [NotNullWhen(true)] out ClassSymbol? classSymbol)
|
protected bool TryGetNamedTypeSymbolByFullName(
|
||||||
|
TypeKind kind,
|
||||||
|
string name,
|
||||||
|
IEnumerable<string> usings,
|
||||||
|
[NotNullWhen(true)] out ClassSymbol? classSymbol
|
||||||
|
)
|
||||||
{
|
{
|
||||||
classSymbol = default;
|
classSymbol = default;
|
||||||
const string globalPrefix = "global::";
|
const string globalPrefix = "global::";
|
||||||
@@ -195,16 +225,26 @@ internal abstract class BaseGenerator
|
|||||||
|
|
||||||
if (symbol is not null && symbol.TypeKind == kind)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var @using in usings)
|
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)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,7 +252,10 @@ internal abstract class BaseGenerator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IReadOnlyList<string> GetMethodParameters(ImmutableArray<IParameterSymbol> parameterSymbols, bool includeType)
|
protected IReadOnlyList<string> GetMethodParameters(
|
||||||
|
ImmutableArray<IParameterSymbol> parameterSymbols,
|
||||||
|
bool includeType
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var methodParameters = new List<string>();
|
var methodParameters = new List<string>();
|
||||||
foreach (var parameterSymbol in parameterSymbols)
|
foreach (var parameterSymbol in parameterSymbols)
|
||||||
@@ -226,7 +269,10 @@ internal abstract class BaseGenerator
|
|||||||
}
|
}
|
||||||
else
|
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;
|
return methodParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IReadOnlyList<ProxyData> GetExtendsProxyData(ProxyData proxyData, ClassSymbol targetClassSymbol)
|
protected IReadOnlyList<ProxyData> GetExtendsProxyData(
|
||||||
|
ProxyData proxyData,
|
||||||
|
ClassSymbol targetClassSymbol
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var extendsProxyClasses = new List<ProxyData>();
|
var extendsProxyClasses = new List<ProxyData>();
|
||||||
foreach (var baseType in targetClassSymbol.BaseTypes)
|
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)
|
if (candidate is not null)
|
||||||
{
|
{
|
||||||
extendsProxyClasses.Add(candidate);
|
extendsProxyClasses.Add(candidate);
|
||||||
@@ -253,10 +304,13 @@ internal abstract class BaseGenerator
|
|||||||
|
|
||||||
internal static string FixType(string type, NullableAnnotation nullableAnnotation)
|
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}?";
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ internal class ExtraFilesGenerator : IFileGenerator
|
|||||||
|
|
||||||
public FileData GenerateFile()
|
public FileData GenerateFile()
|
||||||
{
|
{
|
||||||
return new FileData($"{Name}", $@"//----------------------------------------------------------------------------------------
|
return new FileData(
|
||||||
|
$"{Name}",
|
||||||
|
$@"//----------------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator.
|
// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator.
|
||||||
//
|
//
|
||||||
@@ -61,6 +63,7 @@ namespace ProxyInterfaceGenerator
|
|||||||
|
|
||||||
Internal = 1
|
Internal = 1
|
||||||
}}
|
}}
|
||||||
}}");
|
}}"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ namespace Speckle.ProxyGenerator.FileGenerators;
|
|||||||
internal interface IFileGenerator
|
internal interface IFileGenerator
|
||||||
{
|
{
|
||||||
FileData GenerateFile();
|
FileData GenerateFile();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ namespace Speckle.ProxyGenerator.FileGenerators;
|
|||||||
internal interface IFilesGenerator
|
internal interface IFilesGenerator
|
||||||
{
|
{
|
||||||
IEnumerable<FileData> GenerateFiles();
|
IEnumerable<FileData> GenerateFiles();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ namespace Speckle.ProxyGenerator.FileGenerators;
|
|||||||
|
|
||||||
internal class PartialInterfacesGenerator : BaseGenerator, IFilesGenerator
|
internal class PartialInterfacesGenerator : BaseGenerator, IFilesGenerator
|
||||||
{
|
{
|
||||||
private IReadOnlyCollection<INamedTypeSymbol> _implementedInterfaces = new List<INamedTypeSymbol>();
|
private IReadOnlyCollection<INamedTypeSymbol> _implementedInterfaces =
|
||||||
|
new List<INamedTypeSymbol>();
|
||||||
|
|
||||||
public PartialInterfacesGenerator(Context context, bool supportsNullable) : base(context, supportsNullable)
|
public PartialInterfacesGenerator(Context context, bool supportsNullable)
|
||||||
{
|
: base(context, supportsNullable) { }
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<FileData> GenerateFiles()
|
public IEnumerable<FileData> 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;
|
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;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var interfaceName = ResolveInterfaceNameWithOptionalTypeConstraints(targetClassSymbol.Symbol, pd.ShortInterfaceName);
|
var interfaceName = ResolveInterfaceNameWithOptionalTypeConstraints(
|
||||||
|
targetClassSymbol.Symbol,
|
||||||
|
pd.ShortInterfaceName
|
||||||
|
);
|
||||||
|
|
||||||
fileData = new FileData(
|
fileData = new FileData(
|
||||||
$"{sourceInterfaceSymbol.Symbol.GetFullMetadataName()}.g.cs",
|
$"{sourceInterfaceSymbol.Symbol.GetFullMetadataName()}.g.cs",
|
||||||
@@ -56,12 +77,19 @@ internal class PartialInterfacesGenerator : BaseGenerator, IFilesGenerator
|
|||||||
string ns,
|
string ns,
|
||||||
ClassSymbol classSymbol,
|
ClassSymbol classSymbol,
|
||||||
string interfaceName,
|
string interfaceName,
|
||||||
ProxyData proxyData)
|
ProxyData proxyData
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var extendsProxyClasses = GetExtendsProxyData(proxyData, classSymbol);
|
var extendsProxyClasses = GetExtendsProxyData(proxyData, classSymbol);
|
||||||
_implementedInterfaces = classSymbol.Symbol.ResolveImplementedInterfaces(proxyData.ProxyBaseClasses);
|
_implementedInterfaces = classSymbol.Symbol.ResolveImplementedInterfaces(
|
||||||
var implementedInterfacesNames = _implementedInterfaces.Select(i => i.ToFullyQualifiedDisplayString()).ToArray();
|
proxyData.ProxyBaseClasses
|
||||||
var implements = implementedInterfacesNames.Any() ? $" : {string.Join(", ", implementedInterfacesNames)}" : string.Empty;
|
);
|
||||||
|
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 @new = extendsProxyClasses.Any() ? "new " : string.Empty;
|
||||||
var (namespaceStart, namespaceEnd) = NamespaceBuilder.Build(ns);
|
var (namespaceStart, namespaceEnd) = NamespaceBuilder.Build(ns);
|
||||||
var events = GenerateEvents(classSymbol, proxyData);
|
var events = GenerateEvents(classSymbol, proxyData);
|
||||||
@@ -93,12 +121,16 @@ methods}
|
|||||||
{SupportsNullable.IIf("#nullable restore")}";
|
{SupportsNullable.IIf("#nullable restore")}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private Func<T, bool> InterfaceFilter<T>() where T : ISymbol
|
private Func<T, bool> InterfaceFilter<T>()
|
||||||
|
where T : ISymbol
|
||||||
{
|
{
|
||||||
var hashSet = new HashSet<string>();
|
var hashSet = new HashSet<string>();
|
||||||
foreach (var @interface in _implementedInterfaces)
|
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)
|
foreach (var member in members)
|
||||||
{
|
{
|
||||||
hashSet.Add(member.Name);
|
hashSet.Add(member.Name);
|
||||||
@@ -113,11 +145,19 @@ methods}
|
|||||||
{
|
{
|
||||||
var str = new StringBuilder();
|
var str = new StringBuilder();
|
||||||
|
|
||||||
foreach (var property in MemberHelper.GetPublicProperties(targetClassSymbol, proxyData, InterfaceFilter<IPropertySymbol>()))
|
foreach (
|
||||||
|
var property in MemberHelper.GetPublicProperties(
|
||||||
|
targetClassSymbol,
|
||||||
|
proxyData,
|
||||||
|
InterfaceFilter<IPropertySymbol>()
|
||||||
|
)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var type = GetPropertyType(property, out var isReplaced);
|
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)
|
if (getterSetter is null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -136,7 +176,9 @@ methods}
|
|||||||
str.AppendLine($" {attribute}");
|
str.AppendLine($" {attribute}");
|
||||||
}
|
}
|
||||||
|
|
||||||
str.AppendLine($" {getterSetter.Value.PropertyType} {propertyName} {getterSetter.Value.GetSet}");
|
str.AppendLine(
|
||||||
|
$" {getterSetter.Value.PropertyType} {propertyName} {getterSetter.Value.GetSet}"
|
||||||
|
);
|
||||||
str.AppendLine();
|
str.AppendLine();
|
||||||
}
|
}
|
||||||
return str.ToString();
|
return str.ToString();
|
||||||
@@ -145,7 +187,13 @@ methods}
|
|||||||
private string GenerateMethods(ClassSymbol targetClassSymbol, ProxyData proxyData)
|
private string GenerateMethods(ClassSymbol targetClassSymbol, ProxyData proxyData)
|
||||||
{
|
{
|
||||||
var str = new StringBuilder();
|
var str = new StringBuilder();
|
||||||
foreach (var method in MemberHelper.GetPublicMethods(targetClassSymbol, proxyData, InterfaceFilter<IMethodSymbol>()))
|
foreach (
|
||||||
|
var method in MemberHelper.GetPublicMethods(
|
||||||
|
targetClassSymbol,
|
||||||
|
proxyData,
|
||||||
|
InterfaceFilter<IMethodSymbol>()
|
||||||
|
)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var methodParameters = GetMethodParameters(method.Parameters, true);
|
var methodParameters = GetMethodParameters(method.Parameters, true);
|
||||||
var whereStatement = GetWhereStatementFromMethod(method);
|
var whereStatement = GetWhereStatementFromMethod(method);
|
||||||
@@ -155,7 +203,9 @@ methods}
|
|||||||
str.AppendLine($" {attribute}");
|
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();
|
str.AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,10 +215,19 @@ methods}
|
|||||||
private string GenerateEvents(ClassSymbol targetClassSymbol, ProxyData proxyData)
|
private string GenerateEvents(ClassSymbol targetClassSymbol, ProxyData proxyData)
|
||||||
{
|
{
|
||||||
var str = new StringBuilder();
|
var str = new StringBuilder();
|
||||||
foreach (var @event in MemberHelper.GetPublicEvents(targetClassSymbol, proxyData, InterfaceFilter<IMethodSymbol>()))
|
foreach (
|
||||||
|
var @event in MemberHelper.GetPublicEvents(
|
||||||
|
targetClassSymbol,
|
||||||
|
proxyData,
|
||||||
|
InterfaceFilter<IMethodSymbol>()
|
||||||
|
)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var ps = @event.First().Parameters.First();
|
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())
|
foreach (var attribute in ps.GetAttributesAsList())
|
||||||
{
|
{
|
||||||
@@ -181,4 +240,4 @@ methods}
|
|||||||
|
|
||||||
return str.ToString();
|
return str.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,17 +19,24 @@ internal partial class ProxyClassesGenerator
|
|||||||
foreach (var replacedType in Context.ReplacedTypes)
|
foreach (var replacedType in Context.ReplacedTypes)
|
||||||
{
|
{
|
||||||
TryFindProxyDataByTypeName(replacedType.Key, out var fullTypeName);
|
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 instance =
|
||||||
var proxy = $"proxy{(replacedType.Value + replacedType.Key).GetDeterministicHashCodeAsString()}";
|
$"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(
|
||||||
str.AppendLine($" cfg.CreateMap<{replacedType.Value}, {replacedType.Key}>().ConstructUsing({proxy} => (({classNameProxy}) {proxy})._Instance);");
|
$" 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();
|
||||||
}
|
}
|
||||||
str.AppendLine(" }).CreateMapper();");
|
str.AppendLine(" }).CreateMapper();");
|
||||||
|
|
||||||
return str.ToString();
|
return str.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,17 +12,24 @@ internal partial class ProxyClassesGenerator
|
|||||||
foreach (var replacedType in Context.ReplacedTypes)
|
foreach (var replacedType in Context.ReplacedTypes)
|
||||||
{
|
{
|
||||||
TryFindProxyDataByTypeName(replacedType.Key, out var fullTypeName);
|
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 instance =
|
||||||
var proxy = $"proxy{(replacedType.Value + replacedType.Key).GetDeterministicHashCodeAsString()}";
|
$"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(
|
||||||
str.AppendLine($" Mapster.TypeAdapterConfig<{replacedType.Value}, {replacedType.Key}>.NewConfig().MapWith({proxy} => (({classNameProxy}) {proxy})._Instance);");
|
$" 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();
|
str.AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
return str.ToString();
|
return str.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,8 @@ namespace Speckle.ProxyGenerator.FileGenerators;
|
|||||||
|
|
||||||
internal partial class ProxyClassesGenerator : BaseGenerator, IFilesGenerator
|
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<FileData> GenerateFiles()
|
public IEnumerable<FileData> GenerateFiles()
|
||||||
{
|
{
|
||||||
@@ -27,17 +26,31 @@ internal partial class ProxyClassesGenerator : BaseGenerator, IFilesGenerator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1024:Compare symbols correctly", Justification = "<Pending>")]
|
[SuppressMessage(
|
||||||
|
"MicrosoftCodeAnalysisCorrectness",
|
||||||
|
"RS1024:Compare symbols correctly",
|
||||||
|
Justification = "<Pending>"
|
||||||
|
)]
|
||||||
private bool TryGenerateFile(ProxyData pd, [NotNullWhen(true)] out FileData? fileData)
|
private bool TryGenerateFile(ProxyData pd, [NotNullWhen(true)] out FileData? fileData)
|
||||||
{
|
{
|
||||||
fileData = default;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var interfaceName = ResolveInterfaceNameWithOptionalTypeConstraints(targetClassSymbol.Symbol, pd.FullInterfaceName);
|
var interfaceName = ResolveInterfaceNameWithOptionalTypeConstraints(
|
||||||
|
targetClassSymbol.Symbol,
|
||||||
|
pd.FullInterfaceName
|
||||||
|
);
|
||||||
var className = targetClassSymbol.Symbol.ResolveProxyClassName();
|
var className = targetClassSymbol.Symbol.ResolveProxyClassName();
|
||||||
var constructorName = $"{targetClassSymbol.Symbol.Name}Proxy";
|
var constructorName = $"{targetClassSymbol.Symbol.Name}Proxy";
|
||||||
|
|
||||||
@@ -45,7 +58,14 @@ internal partial class ProxyClassesGenerator : BaseGenerator, IFilesGenerator
|
|||||||
|
|
||||||
fileData = new FileData(
|
fileData = new FileData(
|
||||||
$"{targetClassSymbol.Symbol.GetFullMetadataName()}Proxy.g.cs",
|
$"{targetClassSymbol.Symbol.GetFullMetadataName()}Proxy.g.cs",
|
||||||
CreateProxyClassCode(pd, targetClassSymbol, extendsProxyClasses, interfaceName, className, constructorName)
|
CreateProxyClassCode(
|
||||||
|
pd,
|
||||||
|
targetClassSymbol,
|
||||||
|
extendsProxyClasses,
|
||||||
|
interfaceName,
|
||||||
|
className,
|
||||||
|
constructorName
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -57,7 +77,8 @@ internal partial class ProxyClassesGenerator : BaseGenerator, IFilesGenerator
|
|||||||
IReadOnlyList<ProxyData> extendsProxyClasses,
|
IReadOnlyList<ProxyData> extendsProxyClasses,
|
||||||
string interfaceName,
|
string interfaceName,
|
||||||
string className,
|
string className,
|
||||||
string constructorName)
|
string constructorName
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var firstExtends = extendsProxyClasses.FirstOrDefault();
|
var firstExtends = extendsProxyClasses.FirstOrDefault();
|
||||||
var extends = string.Empty;
|
var extends = string.Empty;
|
||||||
@@ -71,8 +92,10 @@ internal partial class ProxyClassesGenerator : BaseGenerator, IFilesGenerator
|
|||||||
extends = $"global::{firstExtends.NamespaceDot}{firstExtends.ShortMetadataName}Proxy, ";
|
extends = $"global::{firstExtends.NamespaceDot}{firstExtends.ShortMetadataName}Proxy, ";
|
||||||
@base = " : base(instance)";
|
@base = " : base(instance)";
|
||||||
@new = "new ";
|
@new = "new ";
|
||||||
instanceBaseDefinition = $"public {firstExtends.FullQualifiedTypeName} _Instance{firstExtends.FullQualifiedTypeName.GetLastPart()} {{ get; }}";
|
instanceBaseDefinition =
|
||||||
instanceBaseSetter = $"_Instance{firstExtends.FullQualifiedTypeName.GetLastPart()} = instance;";
|
$"public {firstExtends.FullQualifiedTypeName} _Instance{firstExtends.FullQualifiedTypeName.GetLastPart()} {{ get; }}";
|
||||||
|
instanceBaseSetter =
|
||||||
|
$"_Instance{firstExtends.FullQualifiedTypeName.GetLastPart()} = instance;";
|
||||||
}
|
}
|
||||||
|
|
||||||
var @abstract = string.Empty; // targetClassSymbol.Symbol.IsAbstract ? "abstract " : string.Empty;
|
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 (namespaceStart, namespaceEnd) = NamespaceBuilder.Build(pd.Namespace);
|
||||||
|
|
||||||
var accessibility = pd.Accessibility == ProxyClassAccessibility.Internal ? "internal" : "public";
|
var accessibility =
|
||||||
|
pd.Accessibility == ProxyClassAccessibility.Internal ? "internal" : "public";
|
||||||
|
|
||||||
return $@"//----------------------------------------------------------------------------------------
|
return $@"//----------------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
@@ -132,9 +156,7 @@ operators}
|
|||||||
{
|
{
|
||||||
var type = GetPropertyType(property, out var isReplaced);
|
var type = GetPropertyType(property, out var isReplaced);
|
||||||
|
|
||||||
var instance = !property.IsStatic ?
|
var instance = !property.IsStatic ? "_Instance" : $"{targetClassSymbol.Symbol}";
|
||||||
"_Instance" :
|
|
||||||
$"{targetClassSymbol.Symbol}";
|
|
||||||
|
|
||||||
var propertyName = property.GetSanitizedName();
|
var propertyName = property.GetSanitizedName();
|
||||||
var instancePropertyName = $"{instance}.{propertyName}";
|
var instancePropertyName = $"{instance}.{propertyName}";
|
||||||
@@ -169,8 +191,12 @@ operators}
|
|||||||
string set;
|
string set;
|
||||||
if (isReplaced)
|
if (isReplaced)
|
||||||
{
|
{
|
||||||
get = getIsPublic ? $"get => Mapster.TypeAdapter.Adapt<{type}>({instancePropertyName}); " : string.Empty;
|
get = getIsPublic
|
||||||
set = setIsPublic ? $"set => {instancePropertyName} = Mapster.TypeAdapter.Adapt<{property.Type}>(value); " : string.Empty;
|
? $"get => Mapster.TypeAdapter.Adapt<{type}>({instancePropertyName}); "
|
||||||
|
: string.Empty;
|
||||||
|
set = setIsPublic
|
||||||
|
? $"set => {instancePropertyName} = Mapster.TypeAdapter.Adapt<{property.Type}>(value); "
|
||||||
|
: string.Empty;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -183,7 +209,9 @@ operators}
|
|||||||
str.AppendLine($" {attribute}");
|
str.AppendLine($" {attribute}");
|
||||||
}
|
}
|
||||||
|
|
||||||
str.AppendLine($" public {overrideOrVirtual}{type} {propertyName} {{ {get}{set}}}");
|
str.AppendLine(
|
||||||
|
$" public {overrideOrVirtual}{type} {propertyName} {{ {get}{set}}}"
|
||||||
|
);
|
||||||
str.AppendLine();
|
str.AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +236,9 @@ operators}
|
|||||||
methodParameters.Add(MethodParameterBuilder.Build(parameterSymbol, type));
|
methodParameters.Add(MethodParameterBuilder.Build(parameterSymbol, type));
|
||||||
|
|
||||||
// Do not add the '_' for a 'ref' parameter.
|
// 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;
|
string overrideOrVirtual = string.Empty;
|
||||||
@@ -225,7 +255,10 @@ operators}
|
|||||||
overrideOrVirtual = "virtual ";
|
overrideOrVirtual = "virtual ";
|
||||||
}
|
}
|
||||||
|
|
||||||
string returnTypeAsString = GetReplacedTypeAsString(method.ReturnType, out var returnIsReplaced);
|
string returnTypeAsString = GetReplacedTypeAsString(
|
||||||
|
method.ReturnType,
|
||||||
|
out var returnIsReplaced
|
||||||
|
);
|
||||||
|
|
||||||
var whereStatement = GetWhereStatementFromMethod(method);
|
var whereStatement = GetWhereStatementFromMethod(method);
|
||||||
|
|
||||||
@@ -234,12 +267,17 @@ operators}
|
|||||||
str.AppendLine($" {attribute}");
|
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(@" {");
|
str.AppendLine(@" {");
|
||||||
|
|
||||||
foreach (var ps in method.Parameters.Where(p => !p.IsRef()))
|
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()}";
|
string normalOrMap = $" = {ps.GetSanitizedName()}";
|
||||||
if (ps.RefKind == RefKind.Out)
|
if (ps.RefKind == RefKind.Out)
|
||||||
{
|
{
|
||||||
@@ -250,7 +288,8 @@ operators}
|
|||||||
_ = GetParameterType(ps, out var isReplaced); // TODO : response is not used?
|
_ = GetParameterType(ps, out var isReplaced); // TODO : response is not used?
|
||||||
if (isReplaced)
|
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 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")
|
if (returnTypeAsString == "void")
|
||||||
{
|
{
|
||||||
str.AppendLine($" {instance}.{methodName}({string.Join(", ", invokeParameters)});");
|
str.AppendLine(
|
||||||
|
$" {instance}.{methodName}({string.Join(", ", invokeParameters)});"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else
|
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))
|
foreach (var ps in method.Parameters.Where(p => p.RefKind == RefKind.Out))
|
||||||
@@ -279,7 +325,8 @@ operators}
|
|||||||
var type = GetParameterType(ps, out var isReplaced);
|
var type = GetParameterType(ps, out var isReplaced);
|
||||||
if (isReplaced)
|
if (isReplaced)
|
||||||
{
|
{
|
||||||
normalOrMap = $" = Mapster.TypeAdapter.Adapt<{type}>({ps.GetSanitizedName()}_)";
|
normalOrMap =
|
||||||
|
$" = Mapster.TypeAdapter.Adapt<{type}>({ps.GetSanitizedName()}_)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +337,9 @@ operators}
|
|||||||
{
|
{
|
||||||
if (returnIsReplaced)
|
if (returnIsReplaced)
|
||||||
{
|
{
|
||||||
str.AppendLine($" return Mapster.TypeAdapter.Adapt<{returnTypeAsString}>({alternateReturnVariableName});");
|
str.AppendLine(
|
||||||
|
$" return Mapster.TypeAdapter.Adapt<{returnTypeAsString}>({alternateReturnVariableName});"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -312,7 +361,10 @@ operators}
|
|||||||
{
|
{
|
||||||
var name = @event.Key.GetSanitizedName();
|
var name = @event.Key.GetSanitizedName();
|
||||||
var ps = @event.First().Parameters.First();
|
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())
|
foreach (var attribute in ps.GetAttributesAsList())
|
||||||
{
|
{
|
||||||
@@ -340,7 +392,9 @@ operators}
|
|||||||
private string GenerateOperators(ClassSymbol targetClassSymbol, ProxyData proxyData)
|
private string GenerateOperators(ClassSymbol targetClassSymbol, ProxyData proxyData)
|
||||||
{
|
{
|
||||||
var str = new StringBuilder();
|
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())
|
foreach (var attribute in @operator.GetAttributesAsList())
|
||||||
{
|
{
|
||||||
@@ -360,18 +414,26 @@ operators}
|
|||||||
{
|
{
|
||||||
var returnTypeAsString = GetReplacedTypeAsString(@operator.ReturnType, out _);
|
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(@" {");
|
||||||
str.AppendLine($" return ({returnTypeAsString}) {parameter.Name}._Instance;");
|
str.AppendLine(
|
||||||
|
$" return ({returnTypeAsString}) {parameter.Name}._Instance;"
|
||||||
|
);
|
||||||
str.AppendLine(@" }");
|
str.AppendLine(@" }");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var returnTypeAsString = GetReplacedTypeAsString(parameter.Type, out _);
|
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(@" {");
|
||||||
str.AppendLine($" return new {proxyClassName}(({targetClassSymbol.Symbol.Name}) {parameter.Name});");
|
str.AppendLine(
|
||||||
|
$" return new {proxyClassName}(({targetClassSymbol.Symbol.Name}) {parameter.Name});"
|
||||||
|
);
|
||||||
str.AppendLine(@" }");
|
str.AppendLine(@" }");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,4 +442,4 @@ operators}
|
|||||||
|
|
||||||
return str.ToString();
|
return str.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,17 @@ using Microsoft.CodeAnalysis;
|
|||||||
|
|
||||||
namespace Speckle.ProxyGenerator.Models;
|
namespace Speckle.ProxyGenerator.Models;
|
||||||
|
|
||||||
internal record ClassSymbol(INamedTypeSymbol Symbol, List<INamedTypeSymbol> BaseTypes, List<INamedTypeSymbol> Interfaces)
|
internal record ClassSymbol(
|
||||||
|
INamedTypeSymbol Symbol,
|
||||||
|
List<INamedTypeSymbol> BaseTypes,
|
||||||
|
List<INamedTypeSymbol> Interfaces
|
||||||
|
)
|
||||||
{
|
{
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return Symbol.ToDisplayString(NullableFlowState.None, SymbolDisplayFormat.FullyQualifiedFormat);
|
return Symbol.ToDisplayString(
|
||||||
|
NullableFlowState.None,
|
||||||
|
SymbolDisplayFormat.FullyQualifiedFormat
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ internal record ConstraintInfo(string Type, List<string> Items)
|
|||||||
{
|
{
|
||||||
return Items.Any() ? $" where {Type} : {string.Join(", ", Items)}" : string.Empty;
|
return Items.Any() ? $" where {Type} : {string.Join(", ", Items)}" : string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,4 +10,4 @@ internal record Context
|
|||||||
public IDictionary<InterfaceDeclarationSyntax, ProxyData> Candidates { get; init; } = default!;
|
public IDictionary<InterfaceDeclarationSyntax, ProxyData> Candidates { get; init; } = default!;
|
||||||
|
|
||||||
public Dictionary<string, string> ReplacedTypes { get; } = new();
|
public Dictionary<string, string> ReplacedTypes { get; } = new();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
namespace Speckle.ProxyGenerator.Models;
|
namespace Speckle.ProxyGenerator.Models;
|
||||||
|
|
||||||
internal record FileData(string FileName, string Text);
|
internal record FileData(string FileName, string Text);
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ internal class ProxyData
|
|||||||
public ProxyClassAccessibility Accessibility { get; }
|
public ProxyClassAccessibility Accessibility { get; }
|
||||||
public string[] MembersToIgnore { get; }
|
public string[] MembersToIgnore { get; }
|
||||||
|
|
||||||
public ProxyData(string @namespace,
|
public ProxyData(
|
||||||
|
string @namespace,
|
||||||
string namespaceDot,
|
string namespaceDot,
|
||||||
string shortInterfaceName,
|
string shortInterfaceName,
|
||||||
string fullInterfaceName,
|
string fullInterfaceName,
|
||||||
@@ -34,18 +35,25 @@ internal class ProxyData
|
|||||||
string fullMetadataTypeName,
|
string fullMetadataTypeName,
|
||||||
List<string> usings,
|
List<string> usings,
|
||||||
bool proxyBaseClasses,
|
bool proxyBaseClasses,
|
||||||
ProxyClassAccessibility accessibility, string[] membersToIgnore)
|
ProxyClassAccessibility accessibility,
|
||||||
|
string[] membersToIgnore
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Namespace = @namespace ?? throw new ArgumentNullException(nameof(@namespace));
|
Namespace = @namespace ?? throw new ArgumentNullException(nameof(@namespace));
|
||||||
NamespaceDot = namespaceDot ?? throw new ArgumentNullException(nameof(namespaceDot));
|
NamespaceDot = namespaceDot ?? throw new ArgumentNullException(nameof(namespaceDot));
|
||||||
ShortInterfaceName = shortInterfaceName ?? throw new ArgumentNullException(nameof(shortInterfaceName));
|
ShortInterfaceName =
|
||||||
FullInterfaceName = fullInterfaceName ?? throw new ArgumentNullException(nameof(fullInterfaceName));
|
shortInterfaceName ?? throw new ArgumentNullException(nameof(shortInterfaceName));
|
||||||
FullQualifiedTypeName = fullQualifiedTypeName ?? throw new ArgumentNullException(nameof(fullQualifiedTypeName));
|
FullInterfaceName =
|
||||||
ShortMetadataName = shortMetadataTypeName ?? throw new ArgumentNullException(nameof(shortMetadataTypeName));
|
fullInterfaceName ?? throw new ArgumentNullException(nameof(fullInterfaceName));
|
||||||
FullMetadataTypeName = fullMetadataTypeName ?? throw new ArgumentNullException(nameof(fullMetadataTypeName));
|
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));
|
Usings = usings ?? throw new ArgumentNullException(nameof(usings));
|
||||||
ProxyBaseClasses = proxyBaseClasses;
|
ProxyBaseClasses = proxyBaseClasses;
|
||||||
Accessibility = accessibility;
|
Accessibility = accessibility;
|
||||||
MembersToIgnore = membersToIgnore;
|
MembersToIgnore = membersToIgnore;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,9 @@ class ProxyInterfaceCodeGenerator : ISourceGenerator
|
|||||||
|
|
||||||
if (context.SyntaxContextReceiver is not ProxySyntaxReceiver receiver)
|
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
|
// 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)
|
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));
|
context.AddSource("Error.g", SourceText.From(message, Encoding.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,10 +74,17 @@ class ProxyInterfaceCodeGenerator : ISourceGenerator
|
|||||||
};
|
};
|
||||||
|
|
||||||
var attributeData = _proxyAttributeGenerator.GenerateFile();
|
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
|
var context = new Context
|
||||||
{
|
{
|
||||||
@@ -85,11 +95,18 @@ class ProxyInterfaceCodeGenerator : ISourceGenerator
|
|||||||
var partialInterfacesGenerator = new PartialInterfacesGenerator(context, supportsNullable);
|
var partialInterfacesGenerator = new PartialInterfacesGenerator(context, supportsNullable);
|
||||||
foreach (var (fileName, text) in partialInterfacesGenerator.GenerateFiles())
|
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
|
var context = new Context
|
||||||
{
|
{
|
||||||
@@ -100,7 +117,10 @@ class ProxyInterfaceCodeGenerator : ISourceGenerator
|
|||||||
var proxyClassesGenerator = new ProxyClassesGenerator(context, supportsNullable);
|
var proxyClassesGenerator = new ProxyClassesGenerator(context, supportsNullable);
|
||||||
foreach (var (fileName, text) in proxyClassesGenerator.GenerateFiles())
|
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)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ namespace Speckle.ProxyGenerator.SyntaxReceiver;
|
|||||||
|
|
||||||
internal static class AttributeArgumentListParser
|
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)
|
if (argumentList is null || argumentList.Arguments.Count is < 1 or > 4)
|
||||||
{
|
{
|
||||||
@@ -17,13 +20,25 @@ internal static class AttributeArgumentListParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProxyInterfaceGeneratorAttributeArguments result;
|
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
|
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))
|
foreach (var argument in argumentList.Arguments.Skip(1))
|
||||||
@@ -61,7 +76,12 @@ internal static class AttributeArgumentListParser
|
|||||||
return false;
|
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;
|
fullyQualifiedDisplayString = null;
|
||||||
metadataName = null;
|
metadataName = null;
|
||||||
@@ -83,7 +103,13 @@ internal static class AttributeArgumentListParser
|
|||||||
where TEnum : struct
|
where TEnum : struct
|
||||||
{
|
{
|
||||||
var enumAsString = expressionSyntax.ToString();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -94,10 +120,15 @@ internal static class AttributeArgumentListParser
|
|||||||
|
|
||||||
private static bool TryParseAsStringArray(ExpressionSyntax expressionSyntax, out string[] value)
|
private static bool TryParseAsStringArray(ExpressionSyntax expressionSyntax, out string[] value)
|
||||||
{
|
{
|
||||||
if (expressionSyntax is ImplicitArrayCreationExpressionSyntax lmplicitArrayCreationExpressionSyntax)
|
if (
|
||||||
|
expressionSyntax
|
||||||
|
is ImplicitArrayCreationExpressionSyntax lmplicitArrayCreationExpressionSyntax
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var strings = new List<string>();
|
var strings = new List<string>();
|
||||||
foreach (var expression in lmplicitArrayCreationExpressionSyntax.Initializer.Expressions)
|
foreach (
|
||||||
|
var expression in lmplicitArrayCreationExpressionSyntax.Initializer.Expressions
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (expression.GetFirstToken().Value is string s)
|
if (expression.GetFirstToken().Value is string s)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,26 +9,44 @@ namespace Speckle.ProxyGenerator.SyntaxReceiver;
|
|||||||
internal class ProxySyntaxReceiver : ISyntaxContextReceiver
|
internal class ProxySyntaxReceiver : ISyntaxContextReceiver
|
||||||
{
|
{
|
||||||
private const string GlobalPrefix = "global::";
|
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"];
|
private static readonly string[] Modifiers = ["public", "partial"];
|
||||||
public IDictionary<InterfaceDeclarationSyntax, ProxyData> CandidateInterfaces { get; } = new Dictionary<InterfaceDeclarationSyntax, ProxyData>();
|
public IDictionary<InterfaceDeclarationSyntax, ProxyData> CandidateInterfaces { get; } =
|
||||||
|
new Dictionary<InterfaceDeclarationSyntax, ProxyData>();
|
||||||
|
|
||||||
public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
|
public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
|
||||||
{
|
{
|
||||||
var syntaxNode = context.Node;
|
var syntaxNode = context.Node;
|
||||||
var semanticModel = context.SemanticModel;
|
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);
|
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;
|
data = null;
|
||||||
|
|
||||||
@@ -38,7 +56,9 @@ internal class ProxySyntaxReceiver : ISyntaxContextReceiver
|
|||||||
return false;
|
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)
|
if (attributeList is null)
|
||||||
{
|
{
|
||||||
// InterfaceDeclarationSyntax should have the correct attribute
|
// 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 metadataName = fluentBuilderAttributeArguments.MetadataName;
|
||||||
var globalNamespace = string.IsNullOrEmpty(ns) ? string.Empty : $"{GlobalPrefix}{ns}";
|
var globalNamespace = string.IsNullOrEmpty(ns) ? string.Empty : $"{GlobalPrefix}{ns}";
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
namespace Speckle.ProxyGenerator.Types;
|
namespace Speckle.ProxyGenerator.Types;
|
||||||
|
|
||||||
internal record ProxyInterfaceGeneratorAttributeArguments(string FullyQualifiedDisplayString, string MetadataName)
|
internal record ProxyInterfaceGeneratorAttributeArguments(
|
||||||
|
string FullyQualifiedDisplayString,
|
||||||
|
string MetadataName
|
||||||
|
)
|
||||||
{
|
{
|
||||||
public bool ProxyBaseClasses { get; set; }
|
public bool ProxyBaseClasses { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ internal enum ProxyClassAccessibility
|
|||||||
Public = 0,
|
Public = 0,
|
||||||
|
|
||||||
Internal = 1
|
Internal = 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ internal static class MemberHelper
|
|||||||
public static IReadOnlyList<IPropertySymbol> GetPublicProperties(
|
public static IReadOnlyList<IPropertySymbol> GetPublicProperties(
|
||||||
ClassSymbol classSymbol,
|
ClassSymbol classSymbol,
|
||||||
ProxyData proxyData,
|
ProxyData proxyData,
|
||||||
params Func<IPropertySymbol, bool>[] filters)
|
params Func<IPropertySymbol, bool>[] filters
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var allFilters = new List<Func<IPropertySymbol, bool>>(filters)
|
var allFilters = new List<Func<IPropertySymbol, bool>>(filters)
|
||||||
{
|
{
|
||||||
@@ -23,43 +24,46 @@ internal static class MemberHelper
|
|||||||
public static IReadOnlyList<IMethodSymbol> GetPublicMethods(
|
public static IReadOnlyList<IMethodSymbol> GetPublicMethods(
|
||||||
ClassSymbol classSymbol,
|
ClassSymbol classSymbol,
|
||||||
ProxyData proxyData,
|
ProxyData proxyData,
|
||||||
Func<IMethodSymbol, bool>? filter = null)
|
Func<IMethodSymbol, bool>? filter = null
|
||||||
|
)
|
||||||
{
|
{
|
||||||
filter ??= _ => true;
|
filter ??= _ => true;
|
||||||
|
|
||||||
return
|
return GetPublicMembers(
|
||||||
GetPublicMembers(
|
|
||||||
classSymbol,
|
classSymbol,
|
||||||
proxyData,
|
proxyData,
|
||||||
m => m.Kind == SymbolKind.Method,
|
m => m.Kind == SymbolKind.Method,
|
||||||
m => m.MethodKind == MethodKind.Ordinary,
|
m => m.MethodKind == MethodKind.Ordinary,
|
||||||
m => !ExcludedMethods.Contains(m.Name),
|
m => !ExcludedMethods.Contains(m.Name),
|
||||||
filter)
|
filter
|
||||||
|
)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IReadOnlyList<IMethodSymbol> GetPublicStaticOperators(
|
public static IReadOnlyList<IMethodSymbol> GetPublicStaticOperators(
|
||||||
ClassSymbol classSymbol,
|
ClassSymbol classSymbol,
|
||||||
ProxyData proxyData,
|
ProxyData proxyData,
|
||||||
Func<IMethodSymbol, bool>? filter = null)
|
Func<IMethodSymbol, bool>? filter = null
|
||||||
|
)
|
||||||
{
|
{
|
||||||
filter ??= _ => true;
|
filter ??= _ => true;
|
||||||
|
|
||||||
return
|
return GetPublicMembers(
|
||||||
GetPublicMembers(
|
classSymbol,
|
||||||
classSymbol,
|
proxyData,
|
||||||
proxyData,
|
m => m.Kind == SymbolKind.Method,
|
||||||
m => m.Kind == SymbolKind.Method,
|
m => m.MethodKind == MethodKind.Conversion,
|
||||||
m => m.MethodKind == MethodKind.Conversion,
|
m => !ExcludedMethods.Contains(m.Name),
|
||||||
m => !ExcludedMethods.Contains(m.Name),
|
filter
|
||||||
filter)
|
)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IReadOnlyList<IGrouping<ISymbol, IMethodSymbol>> GetPublicEvents(
|
public static IReadOnlyList<IGrouping<ISymbol, IMethodSymbol>> GetPublicEvents(
|
||||||
ClassSymbol classSymbol,
|
ClassSymbol classSymbol,
|
||||||
ProxyData proxyData,
|
ProxyData proxyData,
|
||||||
Func<IMethodSymbol, bool>? filter = null)
|
Func<IMethodSymbol, bool>? filter = null
|
||||||
|
)
|
||||||
{
|
{
|
||||||
filter ??= _ => true;
|
filter ??= _ => true;
|
||||||
|
|
||||||
@@ -68,8 +72,13 @@ internal static class MemberHelper
|
|||||||
return GetPublicMembers(
|
return GetPublicMembers(
|
||||||
classSymbol,
|
classSymbol,
|
||||||
proxyData,
|
proxyData,
|
||||||
m => m.MethodKind is MethodKind.EventAdd or MethodKind.EventRemove/* || m.MethodKind == MethodKind.EventRaise*/,
|
m =>
|
||||||
filter)
|
m.MethodKind
|
||||||
|
is MethodKind.EventAdd
|
||||||
|
or MethodKind.EventRemove /* || m.MethodKind == MethodKind.EventRaise*/
|
||||||
|
,
|
||||||
|
filter
|
||||||
|
)
|
||||||
.GroupBy(e => e.AssociatedSymbol)
|
.GroupBy(e => e.AssociatedSymbol)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
#pragma warning restore RS1024 // Compare symbols correctly
|
#pragma warning restore RS1024 // Compare symbols correctly
|
||||||
@@ -81,9 +90,12 @@ internal static class MemberHelper
|
|||||||
ClassSymbol classSymbol,
|
ClassSymbol classSymbol,
|
||||||
ProxyData proxyData,
|
ProxyData proxyData,
|
||||||
params Func<T, bool>[] filters
|
params Func<T, bool>[] filters
|
||||||
) where T : ISymbol
|
)
|
||||||
|
where T : ISymbol
|
||||||
{
|
{
|
||||||
var membersQuery = classSymbol.Symbol.GetMembers().OfType<T>()
|
var membersQuery = classSymbol
|
||||||
|
.Symbol.GetMembers()
|
||||||
|
.OfType<T>()
|
||||||
.Where(m => m.DeclaredAccessibility == Accessibility.Public);
|
.Where(m => m.DeclaredAccessibility == Accessibility.Public);
|
||||||
|
|
||||||
var f = filters.ToList();
|
var f = filters.ToList();
|
||||||
@@ -106,7 +118,9 @@ internal static class MemberHelper
|
|||||||
|
|
||||||
while (baseType != null && baseType.SpecialType != SpecialType.System_Object)
|
while (baseType != null && baseType.SpecialType != SpecialType.System_Object)
|
||||||
{
|
{
|
||||||
var baseMembers = baseType.GetMembers().OfType<T>()
|
var baseMembers = baseType
|
||||||
|
.GetMembers()
|
||||||
|
.OfType<T>()
|
||||||
.Where(m => m.DeclaredAccessibility == Accessibility.Public)
|
.Where(m => m.DeclaredAccessibility == Accessibility.Public)
|
||||||
.Where(x => !ownMemberNames.Contains(x.Name));
|
.Where(x => !ownMemberNames.Contains(x.Name));
|
||||||
|
|
||||||
@@ -122,4 +136,4 @@ internal static class MemberHelper
|
|||||||
|
|
||||||
return allMembers;
|
return allMembers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,9 @@ internal static class NamespaceBuilder
|
|||||||
{
|
{
|
||||||
var namespaceDefined = !string.IsNullOrEmpty(ns);
|
var namespaceDefined = !string.IsNullOrEmpty(ns);
|
||||||
|
|
||||||
return
|
return (
|
||||||
(
|
|
||||||
namespaceDefined ? $"namespace {ns}\r\n{{" : string.Empty,
|
namespaceDefined ? $"namespace {ns}\r\n{{" : string.Empty,
|
||||||
namespaceDefined ? "}" : string.Empty
|
namespaceDefined ? "}" : string.Empty
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,10 +40,7 @@ public class AkkaTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = _sut.Execute(new[]
|
var result = _sut.Execute(new[] { sourceFile });
|
||||||
{
|
|
||||||
sourceFile
|
|
||||||
});
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Valid.Should().BeTrue();
|
result.Valid.Should().BeTrue();
|
||||||
@@ -54,8 +51,14 @@ public class AkkaTests
|
|||||||
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
||||||
builder.Path.Should().EndWith(fileName.fileName);
|
builder.Path.Should().EndWith(fileName.fileName);
|
||||||
|
|
||||||
if (Write) File.WriteAllText($"../../../Destination/AkkaGenerated/{fileName.fileName}", builder.Text);
|
if (Write)
|
||||||
builder.Text.Should().Be(File.ReadAllText($"../../../Destination/AkkaGenerated/{fileName.fileName}"));
|
File.WriteAllText(
|
||||||
|
$"../../../Destination/AkkaGenerated/{fileName.fileName}",
|
||||||
|
builder.Text
|
||||||
|
);
|
||||||
|
builder
|
||||||
|
.Text.Should()
|
||||||
|
.Be(File.ReadAllText($"../../../Destination/AkkaGenerated/{fileName.fileName}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,17 +27,17 @@ public class InheritedInterfaceTests
|
|||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(false, false)]
|
[InlineData(false, false)]
|
||||||
[InlineData(true, true)]
|
[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 name = "Child";
|
||||||
var interfaceName = "I" + name;
|
var interfaceName = "I" + name;
|
||||||
var proxyName = name + "Proxy";
|
var proxyName = name + "Proxy";
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
string[] fileNames = [
|
string[] fileNames = [$"{Namespace}.{interfaceName}.g.cs", $"{Namespace}.{proxyName}.g.cs"];
|
||||||
$"{Namespace}.{interfaceName}.g.cs",
|
|
||||||
$"{Namespace}.{proxyName}.g.cs"
|
|
||||||
];
|
|
||||||
var path = $"./Source/Disposable/{interfaceName}.cs";
|
var path = $"./Source/Disposable/{interfaceName}.cs";
|
||||||
SourceFile sourceFile = CreateSourceFile(path, name, proxyBaseClass);
|
SourceFile sourceFile = CreateSourceFile(path, name, proxyBaseClass);
|
||||||
|
|
||||||
@@ -69,10 +69,7 @@ public class InheritedInterfaceTests
|
|||||||
var proxyName = name + "Proxy";
|
var proxyName = name + "Proxy";
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
string[] fileNames = [
|
string[] fileNames = [$"{Namespace}.{interfaceName}.g.cs", $"{Namespace}.{proxyName}.g.cs"];
|
||||||
$"{Namespace}.{interfaceName}.g.cs",
|
|
||||||
$"{Namespace}.{proxyName}.g.cs"
|
|
||||||
];
|
|
||||||
|
|
||||||
var path = $"./Source/Disposable/{interfaceName}.cs";
|
var path = $"./Source/Disposable/{interfaceName}.cs";
|
||||||
SourceFile sourceFile = CreateSourceFile(path, name, true);
|
SourceFile sourceFile = CreateSourceFile(path, name, true);
|
||||||
@@ -107,10 +104,7 @@ public class InheritedInterfaceTests
|
|||||||
var proxyName = name + "Proxy";
|
var proxyName = name + "Proxy";
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
string[] fileNames = [
|
string[] fileNames = [$"{Namespace}.{interfaceName}.g.cs", $"{Namespace}.{proxyName}.g.cs"];
|
||||||
$"{Namespace}.{interfaceName}.g.cs",
|
|
||||||
$"{Namespace}.{proxyName}.g.cs"
|
|
||||||
];
|
|
||||||
var interfaceIndex = 1;
|
var interfaceIndex = 1;
|
||||||
var path = $"./Source/Disposable/{interfaceName}.cs";
|
var path = $"./Source/Disposable/{interfaceName}.cs";
|
||||||
SourceFile sourceFile = CreateSourceFile(path, name, true);
|
SourceFile sourceFile = CreateSourceFile(path, name, true);
|
||||||
@@ -161,4 +155,4 @@ public class InheritedInterfaceTests
|
|||||||
builder.Text.Should().Be(File.ReadAllText($"{OutputPath}{fileName.fileName}"));
|
builder.Text.Should().Be(File.ReadAllText($"{OutputPath}{fileName.fileName}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ public class PnPTests
|
|||||||
"ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb.g.cs",
|
"ProxyInterfaceSourceGeneratorTests.Source.PnP.IWeb.g.cs",
|
||||||
"ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext.g.cs",
|
"ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientRuntimeContext.g.cs",
|
||||||
"ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext.g.cs",
|
"ProxyInterfaceSourceGeneratorTests.Source.PnP.IClientContext.g.cs",
|
||||||
|
|
||||||
"Microsoft.SharePoint.Client.ClientObjectProxy.g.cs",
|
"Microsoft.SharePoint.Client.ClientObjectProxy.g.cs",
|
||||||
"Microsoft.SharePoint.Client.SecurableObjectProxy.g.cs",
|
"Microsoft.SharePoint.Client.SecurableObjectProxy.g.cs",
|
||||||
"Microsoft.SharePoint.Client.WebProxy.g.cs",
|
"Microsoft.SharePoint.Client.WebProxy.g.cs",
|
||||||
@@ -99,14 +98,16 @@ public class PnPTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = _sut.Execute(new[]
|
var result = _sut.Execute(
|
||||||
{
|
new[]
|
||||||
sourceFileClientObject,
|
{
|
||||||
sourceFileSec,
|
sourceFileClientObject,
|
||||||
sourceFileWeb,
|
sourceFileSec,
|
||||||
sourceFileClientRuntimeContext,
|
sourceFileWeb,
|
||||||
sourceFileClientContext
|
sourceFileClientRuntimeContext,
|
||||||
});
|
sourceFileClientContext
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Valid.Should().BeTrue();
|
result.Valid.Should().BeTrue();
|
||||||
@@ -117,8 +118,9 @@ public class PnPTests
|
|||||||
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
||||||
builder.Path.Should().EndWith(fileName.fileName);
|
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}"));
|
builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,10 +72,7 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = _sut.Execute(new[]
|
var result = _sut.Execute(new[] { sourceFile });
|
||||||
{
|
|
||||||
sourceFile
|
|
||||||
});
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Valid.Should().BeTrue();
|
result.Valid.Should().BeTrue();
|
||||||
@@ -86,7 +83,6 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
return Verify(results);
|
return Verify(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task GenerateFiles_ForClassWithIgnores()
|
public Task GenerateFiles_ForClassWithIgnores()
|
||||||
{
|
{
|
||||||
@@ -105,19 +101,18 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
AttributeToAddToInterface = new ExtraAttribute
|
AttributeToAddToInterface = new ExtraAttribute
|
||||||
{
|
{
|
||||||
Name = "ProxyInterfaceGenerator.Proxy",
|
Name = "ProxyInterfaceGenerator.Proxy",
|
||||||
ArgumentList = new []
|
ArgumentList = new[]
|
||||||
{
|
{
|
||||||
"typeof(ProxyInterfaceSourceGeneratorTests.Source.Foo2)", "false", "ProxyClassAccessibility.Public",
|
"typeof(ProxyInterfaceSourceGeneratorTests.Source.Foo2)",
|
||||||
|
"false",
|
||||||
|
"ProxyClassAccessibility.Public",
|
||||||
"new []{\"Weird\",\"NotHere\"}"
|
"new []{\"Weird\",\"NotHere\"}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = _sut.Execute(new[]
|
var result = _sut.Execute(new[] { sourceFile });
|
||||||
{
|
|
||||||
sourceFile
|
|
||||||
});
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Valid.Should().BeTrue();
|
result.Valid.Should().BeTrue();
|
||||||
@@ -151,10 +146,7 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = _sut.Execute(new[]
|
var result = _sut.Execute(new[] { sourceFile });
|
||||||
{
|
|
||||||
sourceFile
|
|
||||||
});
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Valid.Should().BeTrue();
|
result.Valid.Should().BeTrue();
|
||||||
@@ -165,7 +157,8 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
||||||
builder.Path.Should().EndWith(fileName.fileName);
|
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}"));
|
builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,10 +186,7 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = _sut.Execute(new[]
|
var result = _sut.Execute(new[] { sourceFile });
|
||||||
{
|
|
||||||
sourceFile
|
|
||||||
});
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Valid.Should().BeTrue();
|
result.Valid.Should().BeTrue();
|
||||||
@@ -207,7 +197,8 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
||||||
builder.Path.Should().EndWith(fileName.fileName);
|
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}"));
|
builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,10 +226,7 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = _sut.Execute(new[]
|
var result = _sut.Execute(new[] { sourceFile });
|
||||||
{
|
|
||||||
sourceFile
|
|
||||||
});
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Valid.Should().BeTrue();
|
result.Valid.Should().BeTrue();
|
||||||
@@ -249,15 +237,13 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
||||||
builder.Path.Should().EndWith(fileName.fileName);
|
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}"));
|
builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = "stef";
|
var name = "stef";
|
||||||
var operatorTest = new OperatorTest
|
var operatorTest = new OperatorTest { Name = name };
|
||||||
{
|
|
||||||
Name = name
|
|
||||||
};
|
|
||||||
string name1 = (string)operatorTest;
|
string name1 = (string)operatorTest;
|
||||||
name1.Should().Be(name);
|
name1.Should().Be(name);
|
||||||
|
|
||||||
@@ -273,11 +259,7 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
public void GenerateFiles_When_NoNamespace_Should_GenerateCorrectFiles()
|
public void GenerateFiles_When_NoNamespace_Should_GenerateCorrectFiles()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var fileNames = new[]
|
var fileNames = new[] { "INoNamespace.g.cs", "NoNamespaceProxy.g.cs" };
|
||||||
{
|
|
||||||
"INoNamespace.g.cs",
|
|
||||||
"NoNamespaceProxy.g.cs"
|
|
||||||
};
|
|
||||||
|
|
||||||
var path = "./Source/INoNamespace.cs";
|
var path = "./Source/INoNamespace.cs";
|
||||||
var sourceFile = new SourceFile
|
var sourceFile = new SourceFile
|
||||||
@@ -292,10 +274,7 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = _sut.Execute(new[]
|
var result = _sut.Execute(new[] { sourceFile });
|
||||||
{
|
|
||||||
sourceFile
|
|
||||||
});
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Valid.Should().BeTrue();
|
result.Valid.Should().BeTrue();
|
||||||
@@ -306,7 +285,8 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
||||||
builder.Path.Should().EndWith(fileName.fileName);
|
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}"));
|
builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -334,10 +314,7 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = _sut.Execute(new[]
|
var result = _sut.Execute(new[] { sourceFile });
|
||||||
{
|
|
||||||
sourceFile
|
|
||||||
});
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Valid.Should().BeTrue();
|
result.Valid.Should().BeTrue();
|
||||||
@@ -348,7 +325,8 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
var builder = result.Files[fileName.index + 1]; // +1 means skip the attribute
|
||||||
builder.Path.Should().EndWith(fileName.fileName);
|
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}"));
|
builder.Text.Should().Be(File.ReadAllText($"../../../Destination/{fileName.fileName}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,7 +337,8 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
// Arrange
|
// Arrange
|
||||||
var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs";
|
var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs";
|
||||||
var interfaceFilename = "ProxyInterfaceSourceGeneratorTests.Source.IPersonExtends.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 path = "./Source/IPersonExtends.cs";
|
||||||
var sourceFile = new SourceFile
|
var sourceFile = new SourceFile
|
||||||
@@ -369,7 +348,11 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
AttributeToAddToInterface = new ExtraAttribute
|
AttributeToAddToInterface = new ExtraAttribute
|
||||||
{
|
{
|
||||||
Name = "ProxyInterfaceGenerator.Proxy",
|
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);
|
@interface.FilePath.Should().EndWith(interfaceFilename);
|
||||||
|
|
||||||
var interfaceCode = @interface.ToString();
|
var interfaceCode = @interface.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{interfaceFilename}", interfaceCode);
|
if (Write)
|
||||||
interfaceCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceFilename}"));
|
File.WriteAllText($"../../../Destination/{interfaceFilename}", interfaceCode);
|
||||||
|
interfaceCode
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(File.ReadAllText($"../../../Destination/{interfaceFilename}"));
|
||||||
|
|
||||||
// Assert Proxy
|
// Assert Proxy
|
||||||
var proxyClass = result.Files[2].SyntaxTree;
|
var proxyClass = result.Files[2].SyntaxTree;
|
||||||
proxyClass.FilePath.Should().EndWith(proxyClassFilename);
|
proxyClass.FilePath.Should().EndWith(proxyClassFilename);
|
||||||
|
|
||||||
var proxyCode = proxyClass.ToString();
|
var proxyCode = proxyClass.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{proxyClassFilename}", proxyCode);
|
if (Write)
|
||||||
proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassFilename}"));
|
File.WriteAllText($"../../../Destination/{proxyClassFilename}", proxyCode);
|
||||||
|
proxyCode
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(File.ReadAllText($"../../../Destination/{proxyClassFilename}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -406,7 +397,8 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var interfaceFilename = "ProxyInterfaceSourceGeneratorTests.Source.ITestClassInternal.g.cs";
|
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 path = "./Source/ITestClassInternal.cs";
|
||||||
var sourceFile = new SourceFile
|
var sourceFile = new SourceFile
|
||||||
@@ -416,7 +408,11 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
AttributeToAddToInterface = new ExtraAttribute
|
AttributeToAddToInterface = new ExtraAttribute
|
||||||
{
|
{
|
||||||
Name = "ProxyInterfaceGenerator.Proxy",
|
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);
|
@interface.FilePath.Should().EndWith(interfaceFilename);
|
||||||
|
|
||||||
var interfaceCode = @interface.ToString();
|
var interfaceCode = @interface.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{interfaceFilename}", interfaceCode);
|
if (Write)
|
||||||
interfaceCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceFilename}"));
|
File.WriteAllText($"../../../Destination/{interfaceFilename}", interfaceCode);
|
||||||
|
interfaceCode
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(File.ReadAllText($"../../../Destination/{interfaceFilename}"));
|
||||||
|
|
||||||
// Assert Proxy
|
// Assert Proxy
|
||||||
var proxyClass = result.Files[2].SyntaxTree;
|
var proxyClass = result.Files[2].SyntaxTree;
|
||||||
proxyClass.FilePath.Should().EndWith(proxyClassFilename);
|
proxyClass.FilePath.Should().EndWith(proxyClassFilename);
|
||||||
|
|
||||||
var proxyCode = proxyClass.ToString();
|
var proxyCode = proxyClass.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{proxyClassFilename}", proxyCode);
|
if (Write)
|
||||||
proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassFilename}"));
|
File.WriteAllText($"../../../Destination/{proxyClassFilename}", proxyCode);
|
||||||
|
proxyCode
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(File.ReadAllText($"../../../Destination/{proxyClassFilename}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -489,41 +493,56 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
var attribute = result.Files[0].SyntaxTree;
|
var attribute = result.Files[0].SyntaxTree;
|
||||||
attribute.FilePath.Should().EndWith(attributeFilename);
|
attribute.FilePath.Should().EndWith(attributeFilename);
|
||||||
|
|
||||||
|
|
||||||
// Assert interface Human
|
// Assert interface Human
|
||||||
var interfaceHuman = result.Files[1].SyntaxTree;
|
var interfaceHuman = result.Files[1].SyntaxTree;
|
||||||
interfaceHuman.FilePath.Should().EndWith(interfaceHumanFilename);
|
interfaceHuman.FilePath.Should().EndWith(interfaceHumanFilename);
|
||||||
|
|
||||||
var interfaceCodeHuman = interfaceHuman.ToString();
|
var interfaceCodeHuman = interfaceHuman.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{interfaceHumanFilename}", interfaceCodeHuman);
|
if (Write)
|
||||||
interfaceCodeHuman.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceHumanFilename}"));
|
File.WriteAllText($"../../../Destination/{interfaceHumanFilename}", interfaceCodeHuman);
|
||||||
|
interfaceCodeHuman
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(File.ReadAllText($"../../../Destination/{interfaceHumanFilename}"));
|
||||||
|
|
||||||
// Assert interface Person
|
// Assert interface Person
|
||||||
var interfacePerson = result.Files[2].SyntaxTree;
|
var interfacePerson = result.Files[2].SyntaxTree;
|
||||||
interfacePerson.FilePath.Should().EndWith(interfacePersonFilename);
|
interfacePerson.FilePath.Should().EndWith(interfacePersonFilename);
|
||||||
|
|
||||||
var interfaceCodePerson = interfacePerson.ToString();
|
var interfaceCodePerson = interfacePerson.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{interfacePersonFilename}", interfaceCodePerson);
|
if (Write)
|
||||||
interfaceCodePerson.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfacePersonFilename}"));
|
File.WriteAllText(
|
||||||
|
$"../../../Destination/{interfacePersonFilename}",
|
||||||
|
interfaceCodePerson
|
||||||
|
);
|
||||||
|
interfaceCodePerson
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(File.ReadAllText($"../../../Destination/{interfacePersonFilename}"));
|
||||||
|
|
||||||
// Assert Proxy Human
|
// Assert Proxy Human
|
||||||
var proxyClassHuman = result.Files[3].SyntaxTree;
|
var proxyClassHuman = result.Files[3].SyntaxTree;
|
||||||
proxyClassHuman.FilePath.Should().EndWith(proxyClassHumanFilename);
|
proxyClassHuman.FilePath.Should().EndWith(proxyClassHumanFilename);
|
||||||
|
|
||||||
var proxyCodeHuman = proxyClassHuman.ToString();
|
var proxyCodeHuman = proxyClassHuman.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{proxyClassHumanFilename}", proxyCodeHuman);
|
if (Write)
|
||||||
proxyCodeHuman.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassHumanFilename}"));
|
File.WriteAllText($"../../../Destination/{proxyClassHumanFilename}", proxyCodeHuman);
|
||||||
|
proxyCodeHuman
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(File.ReadAllText($"../../../Destination/{proxyClassHumanFilename}"));
|
||||||
|
|
||||||
// Assert Proxy Person
|
// Assert Proxy Person
|
||||||
var proxyClassPerson = result.Files[4].SyntaxTree;
|
var proxyClassPerson = result.Files[4].SyntaxTree;
|
||||||
proxyClassPerson.FilePath.Should().EndWith(proxyClassPersonFilename);
|
proxyClassPerson.FilePath.Should().EndWith(proxyClassPersonFilename);
|
||||||
|
|
||||||
var proxyCode = proxyClassPerson.ToString();
|
var proxyCode = proxyClassPerson.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{proxyClassPersonFilename}", proxyCode);
|
if (Write)
|
||||||
proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassPersonFilename}"));
|
File.WriteAllText($"../../../Destination/{proxyClassPersonFilename}", proxyCode);
|
||||||
|
proxyCode
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(File.ReadAllText($"../../../Destination/{proxyClassPersonFilename}"));
|
||||||
|
|
||||||
var personProxy = new PersonProxy(new Person());
|
var personProxy = new PersonProxy(new Person());
|
||||||
|
|
||||||
@@ -538,9 +557,11 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs";
|
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 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 proxyClassIHttpMessageInvokerFilename = "System.Net.Http.HttpMessageInvokerProxy.g.cs";
|
||||||
|
|
||||||
var pathIHttpClient = "./Source/IHttpClient.cs";
|
var pathIHttpClient = "./Source/IHttpClient.cs";
|
||||||
@@ -578,41 +599,69 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
var attribute = result.Files[0].SyntaxTree;
|
var attribute = result.Files[0].SyntaxTree;
|
||||||
attribute.FilePath.Should().EndWith(attributeFilename);
|
attribute.FilePath.Should().EndWith(attributeFilename);
|
||||||
|
|
||||||
|
|
||||||
// Assert interface IHttpClient
|
// Assert interface IHttpClient
|
||||||
var interfaceIHttpClient = result.Files[1].SyntaxTree;
|
var interfaceIHttpClient = result.Files[1].SyntaxTree;
|
||||||
interfaceIHttpClient.FilePath.Should().EndWith(interfaceIHttpClientFilename);
|
interfaceIHttpClient.FilePath.Should().EndWith(interfaceIHttpClientFilename);
|
||||||
|
|
||||||
var interfaceCodeIHttpClient = interfaceIHttpClient.ToString();
|
var interfaceCodeIHttpClient = interfaceIHttpClient.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{interfaceIHttpClientFilename}", interfaceCodeIHttpClient);
|
if (Write)
|
||||||
interfaceCodeIHttpClient.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceIHttpClientFilename}"));
|
File.WriteAllText(
|
||||||
|
$"../../../Destination/{interfaceIHttpClientFilename}",
|
||||||
|
interfaceCodeIHttpClient
|
||||||
|
);
|
||||||
|
interfaceCodeIHttpClient
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(File.ReadAllText($"../../../Destination/{interfaceIHttpClientFilename}"));
|
||||||
|
|
||||||
// Assert interface IHttpMessageInvoker
|
// Assert interface IHttpMessageInvoker
|
||||||
var interfaceIMessageInvoker = result.Files[2].SyntaxTree;
|
var interfaceIMessageInvoker = result.Files[2].SyntaxTree;
|
||||||
interfaceIMessageInvoker.FilePath.Should().EndWith(interfaceIHttpMessageInvokerFilename);
|
interfaceIMessageInvoker.FilePath.Should().EndWith(interfaceIHttpMessageInvokerFilename);
|
||||||
|
|
||||||
var interfaceCodeIMessageInvoker = interfaceIMessageInvoker.ToString();
|
var interfaceCodeIMessageInvoker = interfaceIMessageInvoker.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{interfaceIHttpMessageInvokerFilename}", interfaceCodeIMessageInvoker);
|
if (Write)
|
||||||
interfaceCodeIMessageInvoker.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceIHttpMessageInvokerFilename}"));
|
File.WriteAllText(
|
||||||
|
$"../../../Destination/{interfaceIHttpMessageInvokerFilename}",
|
||||||
|
interfaceCodeIMessageInvoker
|
||||||
|
);
|
||||||
|
interfaceCodeIMessageInvoker
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(
|
||||||
|
File.ReadAllText($"../../../Destination/{interfaceIHttpMessageInvokerFilename}")
|
||||||
|
);
|
||||||
|
|
||||||
// Assert Proxy IHttpClient
|
// Assert Proxy IHttpClient
|
||||||
var proxyClassIHttpClient = result.Files[3].SyntaxTree;
|
var proxyClassIHttpClient = result.Files[3].SyntaxTree;
|
||||||
proxyClassIHttpClient.FilePath.Should().EndWith(proxyClassIHttpClientFilename);
|
proxyClassIHttpClient.FilePath.Should().EndWith(proxyClassIHttpClientFilename);
|
||||||
|
|
||||||
var proxyCodeIHttpClient = proxyClassIHttpClient.ToString();
|
var proxyCodeIHttpClient = proxyClassIHttpClient.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{proxyClassIHttpClientFilename}", proxyCodeIHttpClient);
|
if (Write)
|
||||||
proxyCodeIHttpClient.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassIHttpClientFilename}"));
|
File.WriteAllText(
|
||||||
|
$"../../../Destination/{proxyClassIHttpClientFilename}",
|
||||||
|
proxyCodeIHttpClient
|
||||||
|
);
|
||||||
|
proxyCodeIHttpClient
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(File.ReadAllText($"../../../Destination/{proxyClassIHttpClientFilename}"));
|
||||||
|
|
||||||
// Assert Proxy IHttpMessageInvoker
|
// Assert Proxy IHttpMessageInvoker
|
||||||
var proxyClassIMessageInvoker = result.Files[4].SyntaxTree;
|
var proxyClassIMessageInvoker = result.Files[4].SyntaxTree;
|
||||||
proxyClassIMessageInvoker.FilePath.Should().EndWith(proxyClassIHttpMessageInvokerFilename);
|
proxyClassIMessageInvoker.FilePath.Should().EndWith(proxyClassIHttpMessageInvokerFilename);
|
||||||
|
|
||||||
var proxyIMessageInvoker = proxyClassIMessageInvoker.ToString();
|
var proxyIMessageInvoker = proxyClassIMessageInvoker.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{proxyClassIHttpMessageInvokerFilename}", proxyIMessageInvoker);
|
if (Write)
|
||||||
proxyIMessageInvoker.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassIHttpMessageInvokerFilename}"));
|
File.WriteAllText(
|
||||||
|
$"../../../Destination/{proxyClassIHttpMessageInvokerFilename}",
|
||||||
|
proxyIMessageInvoker
|
||||||
|
);
|
||||||
|
proxyIMessageInvoker
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(
|
||||||
|
File.ReadAllText($"../../../Destination/{proxyClassIHttpMessageInvokerFilename}")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -623,8 +672,10 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
foreach (var x in new[] { 1, 2 })
|
foreach (var x in new[] { 1, 2 })
|
||||||
{
|
{
|
||||||
var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs";
|
var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs";
|
||||||
var interfaceFilename = $"ProxyInterfaceSourceGeneratorTests.Namespace{x}.I{@class}.g.cs";
|
var interfaceFilename =
|
||||||
var proxyClassFilename = $"ProxyInterfaceSourceGeneratorTests.Namespace{x}.{@class}Proxy.g.cs";
|
$"ProxyInterfaceSourceGeneratorTests.Namespace{x}.I{@class}.g.cs";
|
||||||
|
var proxyClassFilename =
|
||||||
|
$"ProxyInterfaceSourceGeneratorTests.Namespace{x}.{@class}Proxy.g.cs";
|
||||||
|
|
||||||
var path = $"./Source/I{@class}{x}.cs";
|
var path = $"./Source/I{@class}{x}.cs";
|
||||||
var sourceFile = new SourceFile
|
var sourceFile = new SourceFile
|
||||||
@@ -634,7 +685,11 @@ public class ProxyInterfaceSourceGeneratorTest
|
|||||||
AttributeToAddToInterface = new ExtraAttribute
|
AttributeToAddToInterface = new ExtraAttribute
|
||||||
{
|
{
|
||||||
Name = "ProxyInterfaceGenerator.Proxy",
|
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);
|
@interface.FilePath.Should().EndWith(interfaceFilename);
|
||||||
|
|
||||||
var interfaceCode = @interface.ToString();
|
var interfaceCode = @interface.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{interfaceFilename}", interfaceCode);
|
if (Write)
|
||||||
interfaceCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceFilename}"));
|
File.WriteAllText($"../../../Destination/{interfaceFilename}", interfaceCode);
|
||||||
|
interfaceCode
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(File.ReadAllText($"../../../Destination/{interfaceFilename}"));
|
||||||
|
|
||||||
// Assert Proxy
|
// Assert Proxy
|
||||||
var proxyClass = result.Files[2].SyntaxTree;
|
var proxyClass = result.Files[2].SyntaxTree;
|
||||||
proxyClass.FilePath.Should().EndWith(proxyClassFilename);
|
proxyClass.FilePath.Should().EndWith(proxyClassFilename);
|
||||||
|
|
||||||
var proxyCode = proxyClass.ToString();
|
var proxyCode = proxyClass.ToString();
|
||||||
if (Write) File.WriteAllText($"../../../Destination/{proxyClassFilename}", proxyCode);
|
if (Write)
|
||||||
proxyCode.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassFilename}"));
|
File.WriteAllText($"../../../Destination/{proxyClassFilename}", proxyCode);
|
||||||
|
proxyCode
|
||||||
|
.Should()
|
||||||
|
.NotBeNullOrEmpty()
|
||||||
|
.And.Be(File.ReadAllText($"../../../Destination/{proxyClassFilename}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source.AkkaActor
|
namespace ProxyInterfaceSourceGeneratorTests.Source.AkkaActor
|
||||||
{
|
{
|
||||||
public partial interface ILocalActorRefProvider
|
public partial interface ILocalActorRefProvider { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+2
-4
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source.AkkaActor
|
namespace ProxyInterfaceSourceGeneratorTests.Source.AkkaActor
|
||||||
{
|
{
|
||||||
public partial interface ILocalActorRefProvider
|
public partial interface ILocalActorRefProvider { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source;
|
namespace ProxyInterfaceSourceGeneratorTests.Source;
|
||||||
|
|
||||||
public class Bar
|
public class Bar { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
namespace ProxyInterfaceSourceGeneratorTests.Namespace1
|
namespace ProxyInterfaceSourceGeneratorTests.Namespace1
|
||||||
{
|
{
|
||||||
public class ClassInNamespace
|
public class ClassInNamespace { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
namespace ProxyInterfaceSourceGeneratorTests.Namespace2
|
namespace ProxyInterfaceSourceGeneratorTests.Namespace2
|
||||||
{
|
{
|
||||||
public class ClassInNamespace
|
public class ClassInNamespace { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable
|
namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable
|
||||||
{
|
{
|
||||||
public class Child : Parent
|
public class Child : Parent { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,15 +6,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable
|
|||||||
|
|
||||||
event EventHandler<string>? IUpdate<string>.Update
|
event EventHandler<string>? IUpdate<string>.Update
|
||||||
{
|
{
|
||||||
add
|
add { throw new NotSupportedException(); }
|
||||||
{
|
remove { throw new NotSupportedException(); }
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
remove
|
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDisposable.Dispose()
|
void IDisposable.Dispose()
|
||||||
@@ -22,4 +15,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable
|
|||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable
|
namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable
|
||||||
{
|
{
|
||||||
public partial interface IChild
|
public partial interface IChild { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable
|
namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable
|
||||||
{
|
{
|
||||||
public partial interface IExplicit
|
public partial interface IExplicit { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable
|
namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable
|
||||||
{
|
{
|
||||||
public partial interface IParent
|
public partial interface IParent { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable
|
|||||||
|
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,4 +42,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source.Disposable
|
|||||||
// Dispose(disposing: false);
|
// Dispose(disposing: false);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,13 +20,15 @@ public class Foo2
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
||||||
public Foo2[] Foos { get; set; }= null!;
|
public Foo2[] Foos { get; set; } = null!;
|
||||||
|
|
||||||
public Foo2[] DoSomethingAndGetAnArrayOfFoos()
|
public Foo2[] DoSomethingAndGetAnArrayOfFoos()
|
||||||
{
|
{
|
||||||
return new[] { new Foo2() };
|
return new[] { new Foo2() };
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Weird { get; set; }
|
public int Weird { get; set; }
|
||||||
|
|
||||||
public int Weird2()
|
public int Weird2()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ namespace ProxyInterfaceSourceGeneratorTests.Source
|
|||||||
|
|
||||||
public string GetterOnly => "x";
|
public string GetterOnly => "x";
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose() { }
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
namespace ProxyInterfaceSourceGeneratorTests.Namespace1
|
namespace ProxyInterfaceSourceGeneratorTests.Namespace1
|
||||||
{
|
{
|
||||||
public partial interface IClassInNamespace
|
public partial interface IClassInNamespace { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
namespace ProxyInterfaceSourceGeneratorTests.Namespace2
|
namespace ProxyInterfaceSourceGeneratorTests.Namespace2
|
||||||
{
|
{
|
||||||
public partial interface IClassInNamespace
|
public partial interface IClassInNamespace { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source
|
namespace ProxyInterfaceSourceGeneratorTests.Source
|
||||||
{
|
{
|
||||||
public partial interface IFoo
|
public partial interface IFoo { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source
|
namespace ProxyInterfaceSourceGeneratorTests.Source
|
||||||
{
|
{
|
||||||
public partial interface IFoo2
|
public partial interface IFoo2 { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source
|
namespace ProxyInterfaceSourceGeneratorTests.Source
|
||||||
{
|
{
|
||||||
public partial interface IGeneric
|
public partial interface IGeneric { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source;
|
namespace ProxyInterfaceSourceGeneratorTests.Source;
|
||||||
|
|
||||||
public partial interface IHttpClient : IHttpMessageInvoker
|
public partial interface IHttpClient : IHttpMessageInvoker { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source;
|
namespace ProxyInterfaceSourceGeneratorTests.Source;
|
||||||
|
|
||||||
public partial interface IHttpMessageInvoker
|
public partial interface IHttpMessageInvoker { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source
|
namespace ProxyInterfaceSourceGeneratorTests.Source
|
||||||
{
|
{
|
||||||
public partial interface IHuman
|
public partial interface IHuman { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source;
|
namespace ProxyInterfaceSourceGeneratorTests.Source;
|
||||||
|
|
||||||
public partial interface IMixedVisibility
|
public partial interface IMixedVisibility { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source
|
namespace ProxyInterfaceSourceGeneratorTests.Source
|
||||||
{
|
{
|
||||||
public partial interface IMyStruct
|
public partial interface IMyStruct { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
public partial interface INoNamespace
|
public partial interface INoNamespace { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
// file-scoped namespace !
|
// file-scoped namespace !
|
||||||
namespace ProxyInterfaceSourceGeneratorTests.Source;
|
namespace ProxyInterfaceSourceGeneratorTests.Source;
|
||||||
|
|
||||||
public partial interface IOperatorTest
|
public partial interface IOperatorTest { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
// file-scoped namespace !
|
// file-scoped namespace !
|
||||||
namespace ProxyInterfaceSourceGeneratorTests.Source;
|
namespace ProxyInterfaceSourceGeneratorTests.Source;
|
||||||
|
|
||||||
public partial interface IPerson : IHuman
|
public partial interface IPerson : IHuman { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source
|
namespace ProxyInterfaceSourceGeneratorTests.Source
|
||||||
{
|
{
|
||||||
public partial interface IPersonExtends
|
public partial interface IPersonExtends { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
namespace ProxyInterfaceSourceGeneratorTests.Source
|
namespace ProxyInterfaceSourceGeneratorTests.Source
|
||||||
{
|
{
|
||||||
public partial interface ITestClassInternal
|
public partial interface ITestClassInternal { }
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,7 +6,5 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ProxyInterfaceSourceGeneratorTests.Source
|
namespace ProxyInterfaceSourceGeneratorTests.Source
|
||||||
{
|
{
|
||||||
public interface IÜberGeneric
|
public interface IÜberGeneric { }
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ namespace ProxyInterfaceSourceGeneratorTests.Source;
|
|||||||
public class MixedVisibility
|
public class MixedVisibility
|
||||||
{
|
{
|
||||||
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
|
[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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source;
|
|||||||
public struct MyStruct
|
public struct MyStruct
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ namespace ProxyInterfaceSourceGeneratorTests.Source;
|
|||||||
public class NoNamespace
|
public class NoNamespace
|
||||||
{
|
{
|
||||||
public bool Test { get; set; }
|
public bool Test { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user