add csharpier

This commit is contained in:
Adam Hathcock
2024-05-21 16:34:46 +01:00
parent 1734d5162a
commit e341772cbc
110 changed files with 1096 additions and 656 deletions
@@ -10,6 +10,7 @@ namespace ProxyInterfaceConsumer
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
public event EventHandler<EventArgs> MyEvent = null!;
public int Weird { get; set; }
public int Weird2()
{
return 0;
@@ -3,11 +3,7 @@ using System.Net.Http;
namespace ProxyInterfaceConsumer.Http;
[ProxyInterfaceGenerator.Proxy(typeof(HttpClient), true)]
public partial interface IHttpClient : IHttpMessageInvoker
{
}
public partial interface IHttpClient : IHttpMessageInvoker { }
[ProxyInterfaceGenerator.Proxy(typeof(HttpMessageInvoker))]
public partial interface IHttpMessageInvoker
{
}
public partial interface IHttpMessageInvoker { }
@@ -13,96 +13,212 @@ namespace ProxyInterfaceConsumer.Http;
public static class IHttpClientExtensions
{
#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);
}
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);
}
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);
}
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);
}
#endregion
#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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
#endregion
}
}
@@ -2,7 +2,7 @@ using ProxyInterfaceGenerator;
namespace ProxyInterfaceConsumer
{
[Proxy(typeof(Address), false, ProxyClassAccessibility.Public, new []{"Weird"})]
[Proxy(typeof(Address), false, ProxyClassAccessibility.Public, new[] { "Weird" })]
public partial interface IAddress
{
public void Weird()
@@ -10,4 +10,4 @@ namespace ProxyInterfaceConsumer
_Instance.Weird2();
}
}
}
}
@@ -1,7 +1,5 @@
namespace ProxyInterfaceConsumer
{
// [ProxyInterfaceGenerator.Proxy(typeof(Microsoft.CodeAnalysis.GeneratorExecutionContext))]
public partial interface IGeneratorExecutionContext
{
}
}
public partial interface IGeneratorExecutionContext { }
}
@@ -1,6 +1,4 @@
namespace ProxyInterfaceConsumer
{
public interface IMyInterface
{
}
}
public interface IMyInterface { }
}
@@ -3,7 +3,5 @@ using ProxyInterfaceGenerator;
namespace ProxyInterfaceConsumer
{
[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<>))]
public partial interface IPersonT //<T> where T : struct
{
}
}
{ }
}
@@ -1,9 +1,7 @@
namespace ProxyInterfaceConsumer
{
[ProxyInterfaceGenerator.Proxy(typeof(ProxyInterfaceConsumer.PersonTT<,>))]
public partial interface IPersonTT<T1, T2>
public partial interface IPersonTT<T1, T2>
where T1 : struct
where T2 : class, new()
{
}
}
where T2 : class, new() { }
}
+12 -16
View File
@@ -10,28 +10,30 @@ namespace ProxyInterfaceConsumer
public int Id { get; }
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
public object @object { get; set; }= null!;
public object @object { get; set; } = null!;
public long? NullableLong { get; }
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
public string Name { get; set; }= null!;
public string Name { get; set; } = null!;
public string? StringNullable { get; set; }
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
public Address Address { get; set; }= null!;
public Address Address { get; set; } = null!;
[SuppressMessage("ReSharper", "NullableWarningSuppressionIsUsed")]
public List<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<Address, Address> AddressesDict2 { get; set; } = new Dictionary<Address, Address>();
public Dictionary<string, Address> AddressesDict { get; set; } =
new Dictionary<string, Address>();
public Dictionary<Address, Address> AddressesDict2 { get; set; } =
new Dictionary<Address, Address>();
public E E { get; set; }
[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)
where T1 : struct
@@ -55,9 +57,7 @@ namespace ProxyInterfaceConsumer
return $"Hello {name} !";
}
public void AddWithParams(params string[] values)
{
}
public void AddWithParams(params string[] values) { }
public Address AddAddress(Address a)
{
@@ -66,9 +66,7 @@ namespace ProxyInterfaceConsumer
return a;
}
public void AddAddresses(params Address[] addresses)
{
}
public void AddAddresses(params Address[] addresses) { }
public void In_Out_Ref1(in int a, out int b, ref int c)
{
@@ -83,9 +81,7 @@ namespace ProxyInterfaceConsumer
// return 404;
//}
public void Void()
{
}
public void Void() { }
public Task Method1Async()
{
@@ -1,6 +1,7 @@
namespace ProxyInterfaceConsumer
{
public class PersonT<T> where T : struct
public class PersonT<T>
where T : struct
{
public T TVal { get; set; }
@@ -14,4 +15,4 @@ namespace ProxyInterfaceConsumer
return new PersonT<T>();
}
}
}
}
@@ -8,8 +8,6 @@ namespace ProxyInterfaceConsumer
public T2 TVal2 { get; set; }
public void Call(int x, T1 t1, T2 t2)
{
}
public void Call(int x, T1 t1, T2 t2) { }
}
}
}
+8 -14
View File
@@ -11,10 +11,7 @@ namespace ProxyInterfaceConsumer;
public class Program
{
private static JsonSerializerOptions JsonSerializerOptions = new ()
{
WriteIndented = true
};
private static JsonSerializerOptions JsonSerializerOptions = new() { WriteIndented = true };
public static async Task Main()
{
@@ -24,7 +21,10 @@ public class Program
var result = await ph.GetAsync("https://www.google.nl");
var todo = await ph.GetFromJsonAsync<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());
@@ -41,9 +41,7 @@ public class Program
var ap = new AddressProxy(new Address { HouseNumber = 42 });
ap.HouseNumber = -1;
ap.MyEvent += delegate (object x, EventArgs a)
{
};
ap.MyEvent += delegate(object x, EventArgs a) { };
IPerson p = new PersonProxy(new Person());
p.Name = "test";
@@ -93,11 +91,7 @@ public sealed class Clazz
}
[ProxyInterfaceGenerator.Proxy(typeof(Test))]
public partial interface ITest
{
}
public partial interface ITest { }
[ProxyInterfaceGenerator.Proxy(typeof(Clazz))]
public partial interface IClazz
{
}
public partial interface IClazz { }