From 059886d1ca95841e27c264106235817b3cc48bbc Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Wed, 6 Dec 2023 21:32:07 +0100 Subject: [PATCH] Exclude System.Runtime.CompilerServices.NullableContextAttribute (#66) * HttpClient * . * . * . --- ProxyInterfaceSourceGenerator Solution.sln | 18 + resources/ihttpclient-icon.png | Bin 0 -> 12244 bytes .../ConsoleAppIHttpClient.csproj | 13 + src-examples/ConsoleAppIHttpClient/Program.cs | 13 + src-examples/ConsoleAppIHttpClient/Todo.cs | 4 + .../ProxyInterfaceConsumer/Address.cs | 2 +- .../Http/IHttpClient.cs | 21 +- .../Http/IHttpClientExtensions.cs | 108 +++++ .../ProxyInterfaceConsumer/IAddress.cs | 2 - src-examples/ProxyInterfaceConsumer/Person.cs | 13 +- .../ProxyInterfaceConsumer/Program.cs | 141 +++--- .../ProxyInterfaceConsumer - Backup.csproj | 33 -- src/IHttpClient/IHttpClient.cs | 7 + src/IHttpClient/IHttpClient.csproj | 54 +++ src/IHttpClient/IHttpClientJsonExtensions.cs | 173 ++++++++ src/IHttpClient/IHttpMessageInvoker.cs | 7 + src/IHttpClient/PackageReadme.md | 17 + .../Constants/InternalClassNames.cs | 8 - .../Extensions/SymbolExtensions.cs | 6 +- .../FileGenerators/ProxyClassesGenerator.cs | 5 +- .../ProxyInterfaceSourceGenerator.csproj | 2 +- .../Utils/MemberHelper.cs | 4 +- ...ourceGeneratorTests.Source.HumanProxy.g.cs | 5 + ...urceGeneratorTests.Source.IHttpClient.g.cs | 134 ++++++ ...ratorTests.Source.IHttpMessageInvoker.g.cs | 33 ++ ...aceSourceGeneratorTests.Source.IHuman.g.cs | 2 + ...eGeneratorTests.Source.IPersonExtends.g.cs | 2 + ...eratorTests.Source.PersonExtendsProxy.g.cs | 5 + .../System.Net.Http.HttpClientProxy.g.cs | 410 ++++++++++++++++++ ...stem.Net.Http.HttpMessageInvokerProxy.g.cs | 59 +++ .../ProxyInterfaceSourceGeneratorTest.cs | 82 ++++ .../Source/Human.cs | 5 + .../Source/IHttpClient.cs | 5 + .../Source/IHttpMessageInvoker.cs | 5 + 34 files changed, 1266 insertions(+), 132 deletions(-) create mode 100644 resources/ihttpclient-icon.png create mode 100644 src-examples/ConsoleAppIHttpClient/ConsoleAppIHttpClient.csproj create mode 100644 src-examples/ConsoleAppIHttpClient/Program.cs create mode 100644 src-examples/ConsoleAppIHttpClient/Todo.cs create mode 100644 src-examples/ProxyInterfaceConsumer/Http/IHttpClientExtensions.cs delete mode 100644 src-examples/ProxyInterfaceConsumer/ProxyInterfaceConsumer - Backup.csproj create mode 100644 src/IHttpClient/IHttpClient.cs create mode 100644 src/IHttpClient/IHttpClient.csproj create mode 100644 src/IHttpClient/IHttpClientJsonExtensions.cs create mode 100644 src/IHttpClient/IHttpMessageInvoker.cs create mode 100644 src/IHttpClient/PackageReadme.md delete mode 100644 src/ProxyInterfaceSourceGenerator/Constants/InternalClassNames.cs create mode 100644 tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IHttpClient.g.cs create mode 100644 tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IHttpMessageInvoker.g.cs create mode 100644 tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpClientProxy.g.cs create mode 100644 tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpMessageInvokerProxy.g.cs create mode 100644 tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpClient.cs create mode 100644 tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpMessageInvoker.cs diff --git a/ProxyInterfaceSourceGenerator Solution.sln b/ProxyInterfaceSourceGenerator Solution.sln index 684e76f..5f7017b 100644 --- a/ProxyInterfaceSourceGenerator Solution.sln +++ b/ProxyInterfaceSourceGenerator Solution.sln @@ -32,6 +32,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProxyInterfaceConsumerForAk EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProxyInterfaceConsumerViaNuGet", "src-examples\ProxyInterfaceConsumerViaNuGet\ProxyInterfaceConsumerViaNuGet.csproj", "{1EA000E4-6103-4577-8D98-BDDA3BE458A2}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IHttpClient", "src\IHttpClient\IHttpClient.csproj", "{38C2BB6E-EE23-4C4F-B8D5-A2AD592DE5E3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleAppIHttpClient", "src-examples\ConsoleAppIHttpClient\ConsoleAppIHttpClient.csproj", "{3E93C092-0E42-4200-B71A-5EEE410FE1F5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -74,6 +78,18 @@ Global {1EA000E4-6103-4577-8D98-BDDA3BE458A2}.DebugAttach|Any CPU.Build.0 = Debug|Any CPU {1EA000E4-6103-4577-8D98-BDDA3BE458A2}.Release|Any CPU.ActiveCfg = Release|Any CPU {1EA000E4-6103-4577-8D98-BDDA3BE458A2}.Release|Any CPU.Build.0 = Release|Any CPU + {38C2BB6E-EE23-4C4F-B8D5-A2AD592DE5E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {38C2BB6E-EE23-4C4F-B8D5-A2AD592DE5E3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {38C2BB6E-EE23-4C4F-B8D5-A2AD592DE5E3}.DebugAttach|Any CPU.ActiveCfg = Debug|Any CPU + {38C2BB6E-EE23-4C4F-B8D5-A2AD592DE5E3}.DebugAttach|Any CPU.Build.0 = Debug|Any CPU + {38C2BB6E-EE23-4C4F-B8D5-A2AD592DE5E3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {38C2BB6E-EE23-4C4F-B8D5-A2AD592DE5E3}.Release|Any CPU.Build.0 = Release|Any CPU + {3E93C092-0E42-4200-B71A-5EEE410FE1F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E93C092-0E42-4200-B71A-5EEE410FE1F5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E93C092-0E42-4200-B71A-5EEE410FE1F5}.DebugAttach|Any CPU.ActiveCfg = Debug|Any CPU + {3E93C092-0E42-4200-B71A-5EEE410FE1F5}.DebugAttach|Any CPU.Build.0 = Debug|Any CPU + {3E93C092-0E42-4200-B71A-5EEE410FE1F5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E93C092-0E42-4200-B71A-5EEE410FE1F5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -85,6 +101,8 @@ Global {5F7DA2C5-B908-4B57-9F5F-BADF1216D89C} = {38BA087F-EDA1-4F8A-A140-85B84791B815} {590908DF-A813-467A-94E4-3500020D0D54} = {38BA087F-EDA1-4F8A-A140-85B84791B815} {1EA000E4-6103-4577-8D98-BDDA3BE458A2} = {38BA087F-EDA1-4F8A-A140-85B84791B815} + {38C2BB6E-EE23-4C4F-B8D5-A2AD592DE5E3} = {ED3DA9DD-1E07-444B-A2D7-2DBA280F96D4} + {3E93C092-0E42-4200-B71A-5EEE410FE1F5} = {38BA087F-EDA1-4F8A-A140-85B84791B815} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {585F071D-051D-441C-9C6B-226D9E15A1F5} diff --git a/resources/ihttpclient-icon.png b/resources/ihttpclient-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..291cfe185a3403587448011ced958244210b9d1b GIT binary patch literal 12244 zcmV;_FDuZAP)M<2h9j+tKgr|yk76BRjWSu;DaSgmNd}8kRd~!c;bm3 zJ$n387=Zr~qujZ3=kVdf`}FAp)JF(~lqQ6}_~MIm&N=7Zci+v)&N;aPjzcRcDVaHQ z=95o83D<)34G$P&%ou}#mE7i#y4HqiG(GXT^#YqehL|xN)PPe#Aqy z*l@=kcZ?V@;{5Z^hdU=3a0Kn|zyF@9H@GH*P)dV4h@1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B+f?Q*A5rWb5b`Y2xC*|{SP9`GV-}xTh}fBYVzBg*RR*RBRsUu zfkX||>w_qsS^w*w%>dE%@7w>)x8FcGA(#ijY`FK);Q&?Jbm#_D6rh%C>c}FQIGQT! z$K5GITEkdm9--mdoFyijhB>(FuX*2oKI7|8O?7Xgv0#~iGAg&-c3bo2%|%E5Jq!?A z8Pc|-ee%gCPy;if;>hEtUUBVh$thY?m5Fmg42kmxCdVYJW+bk2fE`1V3JbE9{W4?x z=#dt_3=IdMZX?7wM9$zp*6@F_Ga?fxb_^m0A)SsLJBEO&7B$~`_R$vx_e)!`i214& z8ODlr*|v6Gqxz?WWEn#g^N)pd9_xRVpgzXLq<%2Oy!F;wSFc_T;SE83!Qub56%brs zZr03M!=D`<8D}d{@)dHcXW`V;uQ!_2C3- zm^JtC{)IEY`E25wkzil&s-W1Wh$vVo;{PcIh~W0xwQFJd!{(H*A+T=Uxs=kXoE{UGKsj@imhSj#(~K`a+?%m0EV_qy2_(xdyX>;y`a%DTDkylr zB7~A4zhRQB;cRf*)~#JN&XRHmTt^a7fOHL{h(lFlJjnnfhOuSK7AP4HalKI4$H<%D zqKGI!QDT5z;{Hhngip7@o>rjRjvYHpDLy*V4;V0D*we#$UC@gVVr@$~$$&^&VPWCS znKK(sw>1EA0MtX)>|g)-m)M1P#O)*lM1!0&?85-G9u}(la|kwFL(&RLR30nBImrM~ zHGkc@b??9bK9rvfpmnex2N4B8Q{B6FH}i!j8E||WoZDWxa^-j5eK%*$oZt?`22gOU z;5dq+DAGTr{a<@@OalNA!T`{}0>Z?I1a?$(MFbNAFXKbfvv7M&cLRtBGZPV2b@$Ay is+rkqJ_Zm27(frt3Xcz+nxH)Z0000 + + + Exe + net8.0 + enable + + + + + + + diff --git a/src-examples/ConsoleAppIHttpClient/Program.cs b/src-examples/ConsoleAppIHttpClient/Program.cs new file mode 100644 index 0000000..ead450e --- /dev/null +++ b/src-examples/ConsoleAppIHttpClient/Program.cs @@ -0,0 +1,13 @@ +using System.Net.Http; +using System.Net.Http.Json; + +var httpClient = new HttpClient(); +var httpClientProxy = new HttpClientProxy(httpClient); + +var result = await httpClientProxy.GetAsync("https://www.google.nl"); +var todo = await httpClientProxy.GetFromJsonAsync("https://jsonplaceholder.typicode.com/todos/1"); +var postResult = await httpClientProxy.PostAsJsonAsync("https://jsonplaceholder.typicode.com/todos", new Todo { Id = 123 }); +var patchResult = await httpClientProxy.PatchAsJsonAsync("https://jsonplaceholder.typicode.com/todos", new Todo { Id = 400 }); +var putResult = await httpClientProxy.PutAsJsonAsync("https://jsonplaceholder.typicode.com/todos", new Todo { Id = 444 }); + +int x = 0; \ No newline at end of file diff --git a/src-examples/ConsoleAppIHttpClient/Todo.cs b/src-examples/ConsoleAppIHttpClient/Todo.cs new file mode 100644 index 0000000..158af1b --- /dev/null +++ b/src-examples/ConsoleAppIHttpClient/Todo.cs @@ -0,0 +1,4 @@ +public class Todo +{ + public int Id { get; set; } +} \ No newline at end of file diff --git a/src-examples/ProxyInterfaceConsumer/Address.cs b/src-examples/ProxyInterfaceConsumer/Address.cs index 055c152..c9e80b8 100644 --- a/src-examples/ProxyInterfaceConsumer/Address.cs +++ b/src-examples/ProxyInterfaceConsumer/Address.cs @@ -1,6 +1,6 @@ using System; -namespace DifferentNamespace +namespace ProxyInterfaceConsumer { public class Address { diff --git a/src-examples/ProxyInterfaceConsumer/Http/IHttpClient.cs b/src-examples/ProxyInterfaceConsumer/Http/IHttpClient.cs index d9bae73..cbd0a8a 100644 --- a/src-examples/ProxyInterfaceConsumer/Http/IHttpClient.cs +++ b/src-examples/ProxyInterfaceConsumer/Http/IHttpClient.cs @@ -1,14 +1,13 @@ -namespace ProxyInterfaceConsumer.Http +using System.Net.Http; + +namespace ProxyInterfaceConsumer.Http; + +[ProxyInterfaceGenerator.Proxy(typeof(HttpClient), true)] +public partial interface IHttpClient : IHttpMessageInvoker { - [ProxyInterfaceGenerator.Proxy(typeof(System.Net.Http.HttpClient), true)] - public partial interface IHttpClient : IHttpMessageInvoker - { - - } +} - [ProxyInterfaceGenerator.Proxy(typeof(System.Net.Http.HttpMessageInvoker))] - public partial interface IHttpMessageInvoker - { - - } +[ProxyInterfaceGenerator.Proxy(typeof(HttpMessageInvoker))] +public partial interface IHttpMessageInvoker +{ } \ No newline at end of file diff --git a/src-examples/ProxyInterfaceConsumer/Http/IHttpClientExtensions.cs b/src-examples/ProxyInterfaceConsumer/Http/IHttpClientExtensions.cs new file mode 100644 index 0000000..0ad8080 --- /dev/null +++ b/src-examples/ProxyInterfaceConsumer/Http/IHttpClientExtensions.cs @@ -0,0 +1,108 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Net.Http; +using System.Net.Http.Json; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; +using System.Threading; +using System.Threading.Tasks; + +namespace ProxyInterfaceConsumer.Http; + +public static class IHttpClientExtensions +{ + #region PostAsJsonAsync + public static Task PostAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) + { + return client._Instance.PostAsJsonAsync(requestUri, value, options, cancellationToken); + } + + public static Task PostAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) + { + return client._Instance.PostAsJsonAsync(requestUri, value, options, cancellationToken); + } + + public static Task PostAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, CancellationToken cancellationToken) + { + return client._Instance.PostAsJsonAsync(requestUri, value, options: null, cancellationToken); + } + + public static Task PostAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, CancellationToken cancellationToken) + { + return client._Instance.PostAsJsonAsync(requestUri, value, options: null, cancellationToken); + } + + public static Task PostAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + { + return client._Instance.PostAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken); + } + + public static Task PostAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + { + return client._Instance.PostAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken); + } + #endregion + + #region GetFromJsonAsync + public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, Type type, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, type, options, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, Type type, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, type, options, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, options, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, options, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, Type type, JsonSerializerContext context, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, type, context, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, Type type, JsonSerializerContext context, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, type, context, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, jsonTypeInfo, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, jsonTypeInfo, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, Type type, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, type, options: null, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, Type type, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, type, options: null, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, cancellationToken); + } + #endregion +} \ No newline at end of file diff --git a/src-examples/ProxyInterfaceConsumer/IAddress.cs b/src-examples/ProxyInterfaceConsumer/IAddress.cs index 1366e7f..f7e3242 100644 --- a/src-examples/ProxyInterfaceConsumer/IAddress.cs +++ b/src-examples/ProxyInterfaceConsumer/IAddress.cs @@ -1,5 +1,3 @@ -using DifferentNamespace; - namespace ProxyInterfaceConsumer { [ProxyInterfaceGenerator.Proxy(typeof(Address))] diff --git a/src-examples/ProxyInterfaceConsumer/Person.cs b/src-examples/ProxyInterfaceConsumer/Person.cs index d0e9432..209f687 100644 --- a/src-examples/ProxyInterfaceConsumer/Person.cs +++ b/src-examples/ProxyInterfaceConsumer/Person.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Threading.Tasks; -using DifferentNamespace; namespace ProxyInterfaceConsumer { @@ -71,12 +70,12 @@ namespace ProxyInterfaceConsumer c++; } - public int In_Out_Ref2(in Address a, out Address b, ref Address c) - { - b = new Address(); - c.HouseNumber = 11; - return 404; - } + //public int In_Out_Ref2(in Address a, out Address b, ref Address c) + //{ + // b = new Address(); + // c.HouseNumber = 11; + // return 404; + //} public void Void() { diff --git a/src-examples/ProxyInterfaceConsumer/Program.cs b/src-examples/ProxyInterfaceConsumer/Program.cs index 3d432d3..35e7a76 100644 --- a/src-examples/ProxyInterfaceConsumer/Program.cs +++ b/src-examples/ProxyInterfaceConsumer/Program.cs @@ -1,86 +1,101 @@ using System; using System.Collections.Generic; +using System.Net.Http; +using System.Net.Http.Json; using System.Text.Json; -using DifferentNamespace; +using System.Threading.Tasks; +using ProxyInterfaceConsumer.Http; -namespace ProxyInterfaceConsumer +namespace ProxyInterfaceConsumer; + +public class Program { - public class Program + private static JsonSerializerOptions JsonSerializerOptions = new () { - private static JsonSerializerOptions JsonSerializerOptions = new () + WriteIndented = true + }; + + public static async Task Main() + { + var h = new HttpClient(); + var ph = new HttpClientProxy(h); + + var result = await ph.GetAsync("https://www.google.nl"); + var todo = await ph.GetFromJsonAsync("https://jsonplaceholder.typicode.com/todos/1"); + + var postResult = await h.PostAsJsonAsync("https://jsonplaceholder.typicode.com/todos", new Todo { Id = 123 }); + + var t = new TestProxy(new Test()); + + IPersonT pT = new PersonTProxy(new PersonT()); + pT.TVal = 1; + Console.WriteLine(JsonSerializer.Serialize(pT, JsonSerializerOptions)); + Console.WriteLine(new string('-', 80)); + + //IPersonTT pTT = new PersonTTProxy(new PersonTT()); + //pTT.TVal1 = 42; + //pTT.TVal2 = new Program(); + //Console.WriteLine(JsonSerializer.Serialize(pTT, JsonSerializerOptions)); + //Console.WriteLine(new string('-', 80)); + + var ap = new AddressProxy(new Address { HouseNumber = 42 }); + ap.HouseNumber = -1; + ap.MyEvent += delegate (object x, EventArgs a) { - WriteIndented = true }; - public static void Main() - { - var t = new TestProxy(new Test()); + IPerson p = new PersonProxy(new Person()); + p.Name = "test"; + p.HelloWorld("stef"); + // p.Address = ap; - IPersonT pT = new PersonTProxy(new PersonT()); - pT.TVal = 1; - Console.WriteLine(JsonSerializer.Serialize(pT, JsonSerializerOptions)); - Console.WriteLine(new string('-', 80)); + Console.WriteLine("DefaultValue " + p.DefaultValue()); + Console.WriteLine("DefaultValue " + p.DefaultValue(42)); - //IPersonTT pTT = new PersonTTProxy(new PersonTT()); - //pTT.TVal1 = 42; - //pTT.TVal2 = new Program(); - //Console.WriteLine(JsonSerializer.Serialize(pTT, JsonSerializerOptions)); - //Console.WriteLine(new string('-', 80)); - - var ap = new AddressProxy(new Address { HouseNumber = 42 }); - ap.HouseNumber = -1; - ap.MyEvent += delegate (object x, EventArgs a) - { - }; - - IPerson p = new PersonProxy(new Person()); - p.Name = "test"; - p.HelloWorld("stef"); - // p.Address = ap; - - Console.WriteLine("DefaultValue " + p.DefaultValue()); - Console.WriteLine("DefaultValue " + p.DefaultValue(42)); - - Console.WriteLine(JsonSerializer.Serialize(p, JsonSerializerOptions)); - } + Console.WriteLine(JsonSerializer.Serialize(p, JsonSerializerOptions)); } +} - public class Test +public class Todo +{ + public int Id { get; set; } +} + +public class Test +{ + public int Id { get; set; } + + public Clazz C { get; } + + public IList Cs { get; set; } + + public int AddString(string s) { - public int Id { get; set; } - - public Clazz C { get; } - - public IList Cs { get; set; } - - public int AddString(string s) - { - return 600; - } - - public Test AddTest(Test t) - { - return new Test(); - } - - public Clazz AddClazz(Clazz c) - { - return new Clazz(); - } + return 600; } - public sealed class Clazz + public Test AddTest(Test t) { - public string Name { get; set; } + return new Test(); } - [ProxyInterfaceGenerator.Proxy(typeof(Test))] - public partial interface ITest + public Clazz AddClazz(Clazz c) { + return new Clazz(); } +} - [ProxyInterfaceGenerator.Proxy(typeof(Clazz))] - public partial interface IClazz - { - } +public sealed class Clazz +{ + public string Name { get; set; } +} + +[ProxyInterfaceGenerator.Proxy(typeof(Test))] +public partial interface ITest +{ +} + +[ProxyInterfaceGenerator.Proxy(typeof(Clazz))] +public partial interface IClazz +{ } \ No newline at end of file diff --git a/src-examples/ProxyInterfaceConsumer/ProxyInterfaceConsumer - Backup.csproj b/src-examples/ProxyInterfaceConsumer/ProxyInterfaceConsumer - Backup.csproj deleted file mode 100644 index 6e1a196..0000000 --- a/src-examples/ProxyInterfaceConsumer/ProxyInterfaceConsumer - Backup.csproj +++ /dev/null @@ -1,33 +0,0 @@ - - - - net7.0 - Exe - enable - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/IHttpClient/IHttpClient.cs b/src/IHttpClient/IHttpClient.cs new file mode 100644 index 0000000..f7cc9fd --- /dev/null +++ b/src/IHttpClient/IHttpClient.cs @@ -0,0 +1,7 @@ +// ReSharper disable once CheckNamespace +namespace System.Net.Http; + +[ProxyInterfaceGenerator.Proxy(typeof(HttpClient), true)] +public partial interface IHttpClient : IHttpMessageInvoker +{ +} \ No newline at end of file diff --git a/src/IHttpClient/IHttpClient.csproj b/src/IHttpClient/IHttpClient.csproj new file mode 100644 index 0000000..ae3686c --- /dev/null +++ b/src/IHttpClient/IHttpClient.csproj @@ -0,0 +1,54 @@ + + + + 0.0.1-preview-01 + netstandard2.1;net6.0;net7.0;net8.0 + enable + latest + {38C2BB6E-EE23-4C4F-B8D5-A2AD592DE5E3} + Stef Heyenrath + + IHttpClient + IHttpClient + This project uses source generation to generate an IHttpClient interface and HttpClientProxy from the HttpClient to make it injectable and unit-testable. + HttpClient;interface;IHttpClient;Proxy;HttpClientProxy + MIT + + https://github.com/StefH/ProxyInterfaceGenerator/src/IHttpClient + git + https://github.com/StefH/ProxyInterfaceGenerator/src/IHttpClient + PackageReadme.md + ihttpclient-icon.png + + + + + true + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/src/IHttpClient/IHttpClientJsonExtensions.cs b/src/IHttpClient/IHttpClientJsonExtensions.cs new file mode 100644 index 0000000..3a55272 --- /dev/null +++ b/src/IHttpClient/IHttpClientJsonExtensions.cs @@ -0,0 +1,173 @@ +using System.Diagnostics.CodeAnalysis; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; +using System.Threading; +using System.Threading.Tasks; + +// ReSharper disable once CheckNamespace +namespace System.Net.Http.Json; + +/// +public static class IHttpClientJsonExtensions +{ + #region PostAsJsonAsync + public static Task PostAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) + { + return client._Instance.PostAsJsonAsync(requestUri, value, options, cancellationToken); + } + + public static Task PostAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) + { + return client._Instance.PostAsJsonAsync(requestUri, value, options, cancellationToken); + } + + public static Task PostAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, CancellationToken cancellationToken) + { + return client._Instance.PostAsJsonAsync(requestUri, value, options: null, cancellationToken); + } + + public static Task PostAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, CancellationToken cancellationToken) + { + return client._Instance.PostAsJsonAsync(requestUri, value, options: null, cancellationToken); + } + + public static Task PostAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + { + return client._Instance.PostAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken); + } + + public static Task PostAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + { + return client._Instance.PostAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken); + } + #endregion + +#if NET7_0_OR_GREATER + #region PatchAsJsonAsync + public static Task PatchAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) + { + return client._Instance.PatchAsJsonAsync(requestUri, value, options, cancellationToken); + } + + public static Task PatchAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) + { + return client._Instance.PatchAsJsonAsync(requestUri, value, options, cancellationToken); + } + + public static Task PatchAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, CancellationToken cancellationToken) + { + return client._Instance.PatchAsJsonAsync(requestUri, value, cancellationToken); + } + + public static Task PatchAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, CancellationToken cancellationToken) + { + return client._Instance.PatchAsJsonAsync(requestUri, value, cancellationToken); + } + + public static Task PatchAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + { + return client._Instance.PatchAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken); + } + + public static Task PatchAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + { + return client._Instance.PatchAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken); + } +#endregion +#endif + + #region PutAsJsonAsync + public static Task PutAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) + { + return client._Instance.PutAsJsonAsync(requestUri, value, options, cancellationToken); + } + + public static Task PutAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) + { + return client._Instance.PutAsJsonAsync(requestUri, value, options, cancellationToken); + } + + public static Task PutAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, CancellationToken cancellationToken) + { + return client._Instance.PutAsJsonAsync(requestUri, value, cancellationToken); + } + + public static Task PutAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, CancellationToken cancellationToken) + { + return client._Instance.PutAsJsonAsync(requestUri, value, cancellationToken); + } + + public static Task PutAsJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + { + return client._Instance.PutAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken); + } + + public static Task PutAsJsonAsync(this IHttpClient client, Uri? requestUri, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + { + return client._Instance.PutAsJsonAsync(requestUri, value, jsonTypeInfo, cancellationToken); + } + #endregion + + #region GetFromJsonAsync + public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, Type type, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, type, options, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, Type type, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, type, options, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, options, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, options, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, Type type, JsonSerializerContext context, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, type, context, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, Type type, JsonSerializerContext context, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, type, context, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, jsonTypeInfo, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, jsonTypeInfo, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, Type type, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, type, options: null, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, Type type, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, type, options: null, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, cancellationToken); + } + + public static Task GetFromJsonAsync(this IHttpClient client, Uri? requestUri, CancellationToken cancellationToken = default) + { + return client._Instance.GetFromJsonAsync(requestUri, cancellationToken); + } + #endregion +} \ No newline at end of file diff --git a/src/IHttpClient/IHttpMessageInvoker.cs b/src/IHttpClient/IHttpMessageInvoker.cs new file mode 100644 index 0000000..67d7c10 --- /dev/null +++ b/src/IHttpClient/IHttpMessageInvoker.cs @@ -0,0 +1,7 @@ +// ReSharper disable once CheckNamespace +namespace System.Net.Http; + +[ProxyInterfaceGenerator.Proxy(typeof(HttpMessageInvoker))] +public partial interface IHttpMessageInvoker +{ +} \ No newline at end of file diff --git a/src/IHttpClient/PackageReadme.md b/src/IHttpClient/PackageReadme.md new file mode 100644 index 0000000..bd873d4 --- /dev/null +++ b/src/IHttpClient/PackageReadme.md @@ -0,0 +1,17 @@ +## Info + +This project uses source generation to generate an `IHttpClient` interface and `HttpClientProxy` from the `HttpClient` to make it injectable and unit-testable. + +All the methods and properties from the `HttpClient` are replicated to `IHttpClient`. + +## Use it +``` c# +HttpClient httpClient = new HttpClient(); +IHttpClient httpClientProxy = new HttpClientProxy(httpClient); + +var result = await httpClientProxy.GetAsync("https://www.google.nl"); +var todo = await httpClientProxy.GetFromJsonAsync("https://jsonplaceholder.typicode.com/todos/1"); +var postResult = await httpClientProxy.PostAsJsonAsync("https://jsonplaceholder.typicode.com/todos", new Todo { Id = 123 }); +var patchResult = await httpClientProxy.PatchAsJsonAsync("https://jsonplaceholder.typicode.com/todos", new Todo { Id = 400 }); +var putResult = await httpClientProxy.PutAsJsonAsync("https://jsonplaceholder.typicode.com/todos", new Todo { Id = 444 }); +``` \ No newline at end of file diff --git a/src/ProxyInterfaceSourceGenerator/Constants/InternalClassNames.cs b/src/ProxyInterfaceSourceGenerator/Constants/InternalClassNames.cs deleted file mode 100644 index cdc9a9a..0000000 --- a/src/ProxyInterfaceSourceGenerator/Constants/InternalClassNames.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace ProxyInterfaceSourceGenerator.Constants; - -internal static class InternalClassNames -{ - public const string NullableAttribute = "System.Runtime.CompilerServices.NullableAttribute"; - - public const string AsyncStateMachineAttribute = "System.Runtime.CompilerServices.AsyncStateMachineAttribute"; -} \ No newline at end of file diff --git a/src/ProxyInterfaceSourceGenerator/Extensions/SymbolExtensions.cs b/src/ProxyInterfaceSourceGenerator/Extensions/SymbolExtensions.cs index b76d44e..5d015c5 100644 --- a/src/ProxyInterfaceSourceGenerator/Extensions/SymbolExtensions.cs +++ b/src/ProxyInterfaceSourceGenerator/Extensions/SymbolExtensions.cs @@ -1,6 +1,5 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; -using ProxyInterfaceSourceGenerator.Constants; namespace ProxyInterfaceSourceGenerator.Extensions; @@ -8,8 +7,9 @@ internal static class SymbolExtensions { private static readonly string[] ExcludedAttributes = { - InternalClassNames.AsyncStateMachineAttribute , - InternalClassNames.NullableAttribute + "System.Runtime.CompilerServices.NullableAttribute", + "System.Runtime.CompilerServices.NullableContextAttribute", + "System.Runtime.CompilerServices.AsyncStateMachineAttribute" }; public static string GetAttributesPrefix(this ISymbol symbol) diff --git a/src/ProxyInterfaceSourceGenerator/FileGenerators/ProxyClassesGenerator.cs b/src/ProxyInterfaceSourceGenerator/FileGenerators/ProxyClassesGenerator.cs index df7f5f1..991c013 100644 --- a/src/ProxyInterfaceSourceGenerator/FileGenerators/ProxyClassesGenerator.cs +++ b/src/ProxyInterfaceSourceGenerator/FileGenerators/ProxyClassesGenerator.cs @@ -198,7 +198,10 @@ using System; private string GeneratePublicMethods(ClassSymbol targetClassSymbol, bool proxyBaseClasses) { var str = new StringBuilder(); - foreach (var method in MemberHelper.GetPublicMethods(targetClassSymbol, proxyBaseClasses)) + + var methods = MemberHelper.GetPublicMethods(targetClassSymbol, proxyBaseClasses); + + foreach (var method in methods) { var methodParameters = new List(); var invokeParameters = new List(); diff --git a/src/ProxyInterfaceSourceGenerator/ProxyInterfaceSourceGenerator.csproj b/src/ProxyInterfaceSourceGenerator/ProxyInterfaceSourceGenerator.csproj index e7b557b..b1420b0 100644 --- a/src/ProxyInterfaceSourceGenerator/ProxyInterfaceSourceGenerator.csproj +++ b/src/ProxyInterfaceSourceGenerator/ProxyInterfaceSourceGenerator.csproj @@ -1,7 +1,7 @@ - 0.0.36 + 0.0.37 netstandard2.0 {12344228-91F4-4502-9595-39584E5ABB34} 10 diff --git a/src/ProxyInterfaceSourceGenerator/Utils/MemberHelper.cs b/src/ProxyInterfaceSourceGenerator/Utils/MemberHelper.cs index 2c2bb98..39236b9 100644 --- a/src/ProxyInterfaceSourceGenerator/Utils/MemberHelper.cs +++ b/src/ProxyInterfaceSourceGenerator/Utils/MemberHelper.cs @@ -92,7 +92,7 @@ internal static class MemberHelper } var ownMembers = membersQuery.ToList(); - var ownPropertyNames = ownMembers.Select(x => x.Name); + var ownMemberNames = ownMembers.Select(x => x.Name); if (!proxyBaseClasses) { @@ -106,7 +106,7 @@ internal static class MemberHelper { var baseMembers = baseType.GetMembers().OfType() .Where(m => m.DeclaredAccessibility == Accessibility.Public) - .Where(x => !ownPropertyNames.Contains(x.Name)); + .Where(x => !ownMemberNames.Contains(x.Name)); foreach (var filter in filters) { diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.HumanProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.HumanProxy.g.cs index bd3ee61..eb7e0bf 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.HumanProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.HumanProxy.g.cs @@ -23,6 +23,11 @@ namespace ProxyInterfaceSourceGeneratorTests.Source + public void Dispose() + { + _Instance.Dispose(); + } + diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IHttpClient.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IHttpClient.g.cs new file mode 100644 index 0000000..1ec8623 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IHttpClient.g.cs @@ -0,0 +1,134 @@ +//---------------------------------------------------------------------------------------- +// +// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//---------------------------------------------------------------------------------------- + +#nullable enable +using System; + +namespace ProxyInterfaceSourceGeneratorTests.Source +{ + public partial interface IHttpClient + { + new System.Net.Http.HttpClient _Instance { get; } + + System.Net.IWebProxy DefaultProxy { get; set; } + + System.Net.Http.Headers.HttpRequestHeaders DefaultRequestHeaders { get; } + + System.Version DefaultRequestVersion { get; set; } + + System.Net.Http.HttpVersionPolicy DefaultVersionPolicy { get; set; } + + System.Uri? BaseAddress { get; set; } + + System.TimeSpan Timeout { get; set; } + + long MaxResponseContentBufferSize { get; set; } + + + + System.Threading.Tasks.Task GetStringAsync(string? requestUri); + + System.Threading.Tasks.Task GetStringAsync(System.Uri? requestUri); + + System.Threading.Tasks.Task GetStringAsync(string? requestUri, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task GetStringAsync(System.Uri? requestUri, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task GetByteArrayAsync(string? requestUri); + + System.Threading.Tasks.Task GetByteArrayAsync(System.Uri? requestUri); + + System.Threading.Tasks.Task GetByteArrayAsync(string? requestUri, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task GetByteArrayAsync(System.Uri? requestUri, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task GetStreamAsync(string? requestUri); + + System.Threading.Tasks.Task GetStreamAsync(string? requestUri, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task GetStreamAsync(System.Uri? requestUri); + + System.Threading.Tasks.Task GetStreamAsync(System.Uri? requestUri, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task GetAsync(string? requestUri); + + System.Threading.Tasks.Task GetAsync(System.Uri? requestUri); + + System.Threading.Tasks.Task GetAsync(string? requestUri, System.Net.Http.HttpCompletionOption completionOption); + + System.Threading.Tasks.Task GetAsync(System.Uri? requestUri, System.Net.Http.HttpCompletionOption completionOption); + + System.Threading.Tasks.Task GetAsync(string? requestUri, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task GetAsync(System.Uri? requestUri, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task GetAsync(string? requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task GetAsync(System.Uri? requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task PostAsync(string? requestUri, System.Net.Http.HttpContent? content); + + System.Threading.Tasks.Task PostAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content); + + System.Threading.Tasks.Task PostAsync(string? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task PostAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task PutAsync(string? requestUri, System.Net.Http.HttpContent? content); + + System.Threading.Tasks.Task PutAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content); + + System.Threading.Tasks.Task PutAsync(string? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task PutAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task PatchAsync(string? requestUri, System.Net.Http.HttpContent? content); + + System.Threading.Tasks.Task PatchAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content); + + System.Threading.Tasks.Task PatchAsync(string? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task PatchAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task DeleteAsync(string? requestUri); + + System.Threading.Tasks.Task DeleteAsync(System.Uri? requestUri); + + System.Threading.Tasks.Task DeleteAsync(string? requestUri, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task DeleteAsync(System.Uri? requestUri, System.Threading.CancellationToken cancellationToken); + + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] + System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage request); + + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] + System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption); + + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] + System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken); + + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] + System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task SendAsync(System.Net.Http.HttpRequestMessage request); + + System.Threading.Tasks.Task SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task SendAsync(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption); + + System.Threading.Tasks.Task SendAsync(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken); + + void CancelPendingRequests(); + + + + + } +} +#nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IHttpMessageInvoker.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IHttpMessageInvoker.g.cs new file mode 100644 index 0000000..2bdd002 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IHttpMessageInvoker.g.cs @@ -0,0 +1,33 @@ +//---------------------------------------------------------------------------------------- +// +// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//---------------------------------------------------------------------------------------- + +#nullable enable +using System; + +namespace ProxyInterfaceSourceGeneratorTests.Source +{ + public partial interface IHttpMessageInvoker + { + System.Net.Http.HttpMessageInvoker _Instance { get; } + + + + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] + System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken); + + System.Threading.Tasks.Task SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken); + + void Dispose(); + + + + + } +} +#nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IHuman.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IHuman.g.cs index 6c6318a..11198de 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IHuman.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IHuman.g.cs @@ -22,6 +22,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source + void Dispose(); + diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IPersonExtends.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IPersonExtends.g.cs index d015b6e..fd82868 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IPersonExtends.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IPersonExtends.g.cs @@ -54,6 +54,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source System.Threading.Tasks.Task Method3Async(); + void Dispose(); + diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonExtendsProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonExtendsProxy.g.cs index 08ec654..355b017 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonExtendsProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonExtendsProxy.g.cs @@ -108,6 +108,11 @@ namespace ProxyInterfaceSourceGeneratorTests.Source return result__57684656; } + public void Dispose() + { + _Instance.Dispose(); + } + diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpClientProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpClientProxy.g.cs new file mode 100644 index 0000000..7d41b8b --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpClientProxy.g.cs @@ -0,0 +1,410 @@ +//---------------------------------------------------------------------------------------- +// +// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//---------------------------------------------------------------------------------------- + +#nullable enable +using System; + +namespace ProxyInterfaceSourceGeneratorTests.Source +{ + public partial class HttpClientProxy : ProxyInterfaceSourceGeneratorTests.Source.HttpMessageInvokerProxy, IHttpClient + { + public new System.Net.Http.HttpClient _Instance { get; } + public System.Net.Http.HttpMessageInvoker _InstanceHttpMessageInvoker { get; } + + public System.Net.IWebProxy DefaultProxy { get => System.Net.Http.HttpClient.DefaultProxy; set => System.Net.Http.HttpClient.DefaultProxy = value; } + + public System.Net.Http.Headers.HttpRequestHeaders DefaultRequestHeaders { get => _Instance.DefaultRequestHeaders; } + + public System.Version DefaultRequestVersion { get => _Instance.DefaultRequestVersion; set => _Instance.DefaultRequestVersion = value; } + + public System.Net.Http.HttpVersionPolicy DefaultVersionPolicy { get => _Instance.DefaultVersionPolicy; set => _Instance.DefaultVersionPolicy = value; } + + public System.Uri? BaseAddress { get => _Instance.BaseAddress; set => _Instance.BaseAddress = value; } + + public System.TimeSpan Timeout { get => _Instance.Timeout; set => _Instance.Timeout = value; } + + public long MaxResponseContentBufferSize { get => _Instance.MaxResponseContentBufferSize; set => _Instance.MaxResponseContentBufferSize = value; } + + + + public System.Threading.Tasks.Task GetStringAsync(string? requestUri) + { + string? requestUri_ = requestUri; + var result_1347886741 = _Instance.GetStringAsync(requestUri_); + return result_1347886741; + } + + public System.Threading.Tasks.Task GetStringAsync(System.Uri? requestUri) + { + System.Uri? requestUri_ = requestUri; + var result_1347886741 = _Instance.GetStringAsync(requestUri_); + return result_1347886741; + } + + public System.Threading.Tasks.Task GetStringAsync(string? requestUri, System.Threading.CancellationToken cancellationToken) + { + string? requestUri_ = requestUri; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_1347886741 = _Instance.GetStringAsync(requestUri_, cancellationToken_); + return result_1347886741; + } + + public System.Threading.Tasks.Task GetStringAsync(System.Uri? requestUri, System.Threading.CancellationToken cancellationToken) + { + System.Uri? requestUri_ = requestUri; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_1347886741 = _Instance.GetStringAsync(requestUri_, cancellationToken_); + return result_1347886741; + } + + public System.Threading.Tasks.Task GetByteArrayAsync(string? requestUri) + { + string? requestUri_ = requestUri; + var result__1359336953 = _Instance.GetByteArrayAsync(requestUri_); + return result__1359336953; + } + + public System.Threading.Tasks.Task GetByteArrayAsync(System.Uri? requestUri) + { + System.Uri? requestUri_ = requestUri; + var result__1359336953 = _Instance.GetByteArrayAsync(requestUri_); + return result__1359336953; + } + + public System.Threading.Tasks.Task GetByteArrayAsync(string? requestUri, System.Threading.CancellationToken cancellationToken) + { + string? requestUri_ = requestUri; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result__1359336953 = _Instance.GetByteArrayAsync(requestUri_, cancellationToken_); + return result__1359336953; + } + + public System.Threading.Tasks.Task GetByteArrayAsync(System.Uri? requestUri, System.Threading.CancellationToken cancellationToken) + { + System.Uri? requestUri_ = requestUri; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result__1359336953 = _Instance.GetByteArrayAsync(requestUri_, cancellationToken_); + return result__1359336953; + } + + public System.Threading.Tasks.Task GetStreamAsync(string? requestUri) + { + string? requestUri_ = requestUri; + var result_355326142 = _Instance.GetStreamAsync(requestUri_); + return result_355326142; + } + + public System.Threading.Tasks.Task GetStreamAsync(string? requestUri, System.Threading.CancellationToken cancellationToken) + { + string? requestUri_ = requestUri; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_355326142 = _Instance.GetStreamAsync(requestUri_, cancellationToken_); + return result_355326142; + } + + public System.Threading.Tasks.Task GetStreamAsync(System.Uri? requestUri) + { + System.Uri? requestUri_ = requestUri; + var result_355326142 = _Instance.GetStreamAsync(requestUri_); + return result_355326142; + } + + public System.Threading.Tasks.Task GetStreamAsync(System.Uri? requestUri, System.Threading.CancellationToken cancellationToken) + { + System.Uri? requestUri_ = requestUri; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_355326142 = _Instance.GetStreamAsync(requestUri_, cancellationToken_); + return result_355326142; + } + + public System.Threading.Tasks.Task GetAsync(string? requestUri) + { + string? requestUri_ = requestUri; + var result_1805284658 = _Instance.GetAsync(requestUri_); + return result_1805284658; + } + + public System.Threading.Tasks.Task GetAsync(System.Uri? requestUri) + { + System.Uri? requestUri_ = requestUri; + var result_1805284658 = _Instance.GetAsync(requestUri_); + return result_1805284658; + } + + public System.Threading.Tasks.Task GetAsync(string? requestUri, System.Net.Http.HttpCompletionOption completionOption) + { + string? requestUri_ = requestUri; + System.Net.Http.HttpCompletionOption completionOption_ = completionOption; + var result_1805284658 = _Instance.GetAsync(requestUri_, completionOption_); + return result_1805284658; + } + + public System.Threading.Tasks.Task GetAsync(System.Uri? requestUri, System.Net.Http.HttpCompletionOption completionOption) + { + System.Uri? requestUri_ = requestUri; + System.Net.Http.HttpCompletionOption completionOption_ = completionOption; + var result_1805284658 = _Instance.GetAsync(requestUri_, completionOption_); + return result_1805284658; + } + + public System.Threading.Tasks.Task GetAsync(string? requestUri, System.Threading.CancellationToken cancellationToken) + { + string? requestUri_ = requestUri; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_1805284658 = _Instance.GetAsync(requestUri_, cancellationToken_); + return result_1805284658; + } + + public System.Threading.Tasks.Task GetAsync(System.Uri? requestUri, System.Threading.CancellationToken cancellationToken) + { + System.Uri? requestUri_ = requestUri; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_1805284658 = _Instance.GetAsync(requestUri_, cancellationToken_); + return result_1805284658; + } + + public System.Threading.Tasks.Task GetAsync(string? requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) + { + string? requestUri_ = requestUri; + System.Net.Http.HttpCompletionOption completionOption_ = completionOption; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_1805284658 = _Instance.GetAsync(requestUri_, completionOption_, cancellationToken_); + return result_1805284658; + } + + public System.Threading.Tasks.Task GetAsync(System.Uri? requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) + { + System.Uri? requestUri_ = requestUri; + System.Net.Http.HttpCompletionOption completionOption_ = completionOption; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_1805284658 = _Instance.GetAsync(requestUri_, completionOption_, cancellationToken_); + return result_1805284658; + } + + public System.Threading.Tasks.Task PostAsync(string? requestUri, System.Net.Http.HttpContent? content) + { + string? requestUri_ = requestUri; + System.Net.Http.HttpContent? content_ = content; + var result__1705712948 = _Instance.PostAsync(requestUri_, content_); + return result__1705712948; + } + + public System.Threading.Tasks.Task PostAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content) + { + System.Uri? requestUri_ = requestUri; + System.Net.Http.HttpContent? content_ = content; + var result__1705712948 = _Instance.PostAsync(requestUri_, content_); + return result__1705712948; + } + + public System.Threading.Tasks.Task PostAsync(string? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken) + { + string? requestUri_ = requestUri; + System.Net.Http.HttpContent? content_ = content; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result__1705712948 = _Instance.PostAsync(requestUri_, content_, cancellationToken_); + return result__1705712948; + } + + public System.Threading.Tasks.Task PostAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken) + { + System.Uri? requestUri_ = requestUri; + System.Net.Http.HttpContent? content_ = content; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result__1705712948 = _Instance.PostAsync(requestUri_, content_, cancellationToken_); + return result__1705712948; + } + + public System.Threading.Tasks.Task PutAsync(string? requestUri, System.Net.Http.HttpContent? content) + { + string? requestUri_ = requestUri; + System.Net.Http.HttpContent? content_ = content; + var result_182918739 = _Instance.PutAsync(requestUri_, content_); + return result_182918739; + } + + public System.Threading.Tasks.Task PutAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content) + { + System.Uri? requestUri_ = requestUri; + System.Net.Http.HttpContent? content_ = content; + var result_182918739 = _Instance.PutAsync(requestUri_, content_); + return result_182918739; + } + + public System.Threading.Tasks.Task PutAsync(string? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken) + { + string? requestUri_ = requestUri; + System.Net.Http.HttpContent? content_ = content; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_182918739 = _Instance.PutAsync(requestUri_, content_, cancellationToken_); + return result_182918739; + } + + public System.Threading.Tasks.Task PutAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken) + { + System.Uri? requestUri_ = requestUri; + System.Net.Http.HttpContent? content_ = content; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_182918739 = _Instance.PutAsync(requestUri_, content_, cancellationToken_); + return result_182918739; + } + + public System.Threading.Tasks.Task PatchAsync(string? requestUri, System.Net.Http.HttpContent? content) + { + string? requestUri_ = requestUri; + System.Net.Http.HttpContent? content_ = content; + var result_910894592 = _Instance.PatchAsync(requestUri_, content_); + return result_910894592; + } + + public System.Threading.Tasks.Task PatchAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content) + { + System.Uri? requestUri_ = requestUri; + System.Net.Http.HttpContent? content_ = content; + var result_910894592 = _Instance.PatchAsync(requestUri_, content_); + return result_910894592; + } + + public System.Threading.Tasks.Task PatchAsync(string? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken) + { + string? requestUri_ = requestUri; + System.Net.Http.HttpContent? content_ = content; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_910894592 = _Instance.PatchAsync(requestUri_, content_, cancellationToken_); + return result_910894592; + } + + public System.Threading.Tasks.Task PatchAsync(System.Uri? requestUri, System.Net.Http.HttpContent? content, System.Threading.CancellationToken cancellationToken) + { + System.Uri? requestUri_ = requestUri; + System.Net.Http.HttpContent? content_ = content; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_910894592 = _Instance.PatchAsync(requestUri_, content_, cancellationToken_); + return result_910894592; + } + + public System.Threading.Tasks.Task DeleteAsync(string? requestUri) + { + string? requestUri_ = requestUri; + var result_534537427 = _Instance.DeleteAsync(requestUri_); + return result_534537427; + } + + public System.Threading.Tasks.Task DeleteAsync(System.Uri? requestUri) + { + System.Uri? requestUri_ = requestUri; + var result_534537427 = _Instance.DeleteAsync(requestUri_); + return result_534537427; + } + + public System.Threading.Tasks.Task DeleteAsync(string? requestUri, System.Threading.CancellationToken cancellationToken) + { + string? requestUri_ = requestUri; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_534537427 = _Instance.DeleteAsync(requestUri_, cancellationToken_); + return result_534537427; + } + + public System.Threading.Tasks.Task DeleteAsync(System.Uri? requestUri, System.Threading.CancellationToken cancellationToken) + { + System.Uri? requestUri_ = requestUri; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result_534537427 = _Instance.DeleteAsync(requestUri_, cancellationToken_); + return result_534537427; + } + + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] + public System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage request) + { + System.Net.Http.HttpRequestMessage request_ = request; + var result__989347188 = _Instance.Send(request_); + return result__989347188; + } + + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] + public System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption) + { + System.Net.Http.HttpRequestMessage request_ = request; + System.Net.Http.HttpCompletionOption completionOption_ = completionOption; + var result__989347188 = _Instance.Send(request_, completionOption_); + return result__989347188; + } + + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] + public override System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) + { + System.Net.Http.HttpRequestMessage request_ = request; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result__989347188 = _Instance.Send(request_, cancellationToken_); + return result__989347188; + } + + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] + public System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) + { + System.Net.Http.HttpRequestMessage request_ = request; + System.Net.Http.HttpCompletionOption completionOption_ = completionOption; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result__989347188 = _Instance.Send(request_, completionOption_, cancellationToken_); + return result__989347188; + } + + public System.Threading.Tasks.Task SendAsync(System.Net.Http.HttpRequestMessage request) + { + System.Net.Http.HttpRequestMessage request_ = request; + var result__1161702976 = _Instance.SendAsync(request_); + return result__1161702976; + } + + public override System.Threading.Tasks.Task SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) + { + System.Net.Http.HttpRequestMessage request_ = request; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result__1161702976 = _Instance.SendAsync(request_, cancellationToken_); + return result__1161702976; + } + + public System.Threading.Tasks.Task SendAsync(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption) + { + System.Net.Http.HttpRequestMessage request_ = request; + System.Net.Http.HttpCompletionOption completionOption_ = completionOption; + var result__1161702976 = _Instance.SendAsync(request_, completionOption_); + return result__1161702976; + } + + public System.Threading.Tasks.Task SendAsync(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) + { + System.Net.Http.HttpRequestMessage request_ = request; + System.Net.Http.HttpCompletionOption completionOption_ = completionOption; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result__1161702976 = _Instance.SendAsync(request_, completionOption_, cancellationToken_); + return result__1161702976; + } + + public void CancelPendingRequests() + { + _Instance.CancelPendingRequests(); + } + + + + + + + + public HttpClientProxy(System.Net.Http.HttpClient instance) : base(instance) + { + _Instance = instance; + _InstanceHttpMessageInvoker = instance; + + + } + } +} +#nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpMessageInvokerProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpMessageInvokerProxy.g.cs new file mode 100644 index 0000000..8e95486 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/System.Net.Http.HttpMessageInvokerProxy.g.cs @@ -0,0 +1,59 @@ +//---------------------------------------------------------------------------------------- +// +// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//---------------------------------------------------------------------------------------- + +#nullable enable +using System; + +namespace ProxyInterfaceSourceGeneratorTests.Source +{ + public partial class HttpMessageInvokerProxy : IHttpMessageInvoker + { + public System.Net.Http.HttpMessageInvoker _Instance { get; } + + + + + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] + public virtual System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) + { + System.Net.Http.HttpRequestMessage request_ = request; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result__989347188 = _Instance.Send(request_, cancellationToken_); + return result__989347188; + } + + public virtual System.Threading.Tasks.Task SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) + { + System.Net.Http.HttpRequestMessage request_ = request; + System.Threading.CancellationToken cancellationToken_ = cancellationToken; + var result__1161702976 = _Instance.SendAsync(request_, cancellationToken_); + return result__1161702976; + } + + public void Dispose() + { + _Instance.Dispose(); + } + + + + + + + + public HttpMessageInvokerProxy(System.Net.Http.HttpMessageInvoker instance) + { + _Instance = instance; + + + + } + } +} +#nullable restore \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs index b7f4d4b..d12249f 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/ProxyInterfaceSourceGeneratorTest.cs @@ -448,4 +448,86 @@ public class ProxyInterfaceSourceGeneratorTest c.Should().Be(101); } + + [Fact] + public void GenerateFiles_HttpClient() + { + // Arrange + var attributeFilename = "ProxyInterfaceGenerator.Extra.g.cs"; + var interfaceIHttpClientFilename = "ProxyInterfaceSourceGeneratorTests.Source.IHttpClient.g.cs"; + var proxyClassIHttpClientFilename = "System.Net.Http.HttpClientProxy.g.cs"; + var interfaceIHttpMessageInvokerFilename = "ProxyInterfaceSourceGeneratorTests.Source.IHttpMessageInvoker.g.cs"; + var proxyClassIHttpMessageInvokerFilename = "System.Net.Http.HttpMessageInvokerProxy.g.cs"; + + var pathIHttpClient = "./Source/IHttpClient.cs"; + var sourceFileIHttpClient = new SourceFile + { + Path = pathIHttpClient, + Text = File.ReadAllText(pathIHttpClient), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = "typeof(System.Net.Http.HttpClient)" + } + }; + + var pathIHttpMessageInvoker = "./Source/IHttpMessageInvoker.cs"; + var sourceFileIHttpMessageInvoker = new SourceFile + { + Path = pathIHttpMessageInvoker, + Text = File.ReadAllText(pathIHttpMessageInvoker), + AttributeToAddToInterface = new ExtraAttribute + { + Name = "ProxyInterfaceGenerator.Proxy", + ArgumentList = "typeof(System.Net.Http.HttpMessageInvoker)" + } + }; + + // Act + var result = _sut.Execute(new[] { sourceFileIHttpClient, sourceFileIHttpMessageInvoker }); + + // Assert + result.Valid.Should().BeTrue(); + result.Files.Should().HaveCount(5); + + // Assert attribute + var attribute = result.Files[0].SyntaxTree; + attribute.FilePath.Should().EndWith(attributeFilename); + + + // Assert interface IHttpClient + var interfaceIHttpClient = result.Files[1].SyntaxTree; + interfaceIHttpClient.FilePath.Should().EndWith(interfaceIHttpClientFilename); + + var interfaceCodeIHttpClient = interfaceIHttpClient.ToString(); + if (Write) File.WriteAllText($"../../../Destination/{interfaceIHttpClientFilename}", interfaceCodeIHttpClient); + interfaceCodeIHttpClient.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceIHttpClientFilename}")); + + + // Assert interface IHttpMessageInvoker + var interfaceIMessageInvoker = result.Files[2].SyntaxTree; + interfaceIMessageInvoker.FilePath.Should().EndWith(interfaceIHttpMessageInvokerFilename); + + var interfaceCodeIMessageInvoker = interfaceIMessageInvoker.ToString(); + if (Write) File.WriteAllText($"../../../Destination/{interfaceIHttpMessageInvokerFilename}", interfaceCodeIMessageInvoker); + interfaceCodeIMessageInvoker.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{interfaceIHttpMessageInvokerFilename}")); + + + // Assert Proxy IHttpClient + var proxyClassIHttpClient = result.Files[3].SyntaxTree; + proxyClassIHttpClient.FilePath.Should().EndWith(proxyClassIHttpClientFilename); + + var proxyCodeIHttpClient = proxyClassIHttpClient.ToString(); + if (Write) File.WriteAllText($"../../../Destination/{proxyClassIHttpClientFilename}", proxyCodeIHttpClient); + proxyCodeIHttpClient.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassIHttpClientFilename}")); + + + // Assert Proxy IHttpMessageInvoker + var proxyClassIMessageInvoker = result.Files[4].SyntaxTree; + proxyClassIMessageInvoker.FilePath.Should().EndWith(proxyClassIHttpMessageInvokerFilename); + + var proxyIMessageInvoker = proxyClassIMessageInvoker.ToString(); + if (Write) File.WriteAllText($"../../../Destination/{proxyClassIHttpMessageInvokerFilename}", proxyIMessageInvoker); + proxyIMessageInvoker.Should().NotBeNullOrEmpty().And.Be(File.ReadAllText($"../../../Destination/{proxyClassIHttpMessageInvokerFilename}")); + } } \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Human.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Human.cs index eef45d3..75a9fd2 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Human.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Human.cs @@ -5,5 +5,10 @@ namespace ProxyInterfaceSourceGeneratorTests.Source public bool IsAlive { get; set; } public string GetterOnly => "x"; + + public void Dispose() + { + + } } } \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpClient.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpClient.cs new file mode 100644 index 0000000..d0898e9 --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpClient.cs @@ -0,0 +1,5 @@ +namespace ProxyInterfaceSourceGeneratorTests.Source; + +public partial interface IHttpClient : IHttpMessageInvoker +{ +} \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpMessageInvoker.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpMessageInvoker.cs new file mode 100644 index 0000000..f19317e --- /dev/null +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/IHttpMessageInvoker.cs @@ -0,0 +1,5 @@ +namespace ProxyInterfaceSourceGeneratorTests.Source; + +public partial interface IHttpMessageInvoker +{ +} \ No newline at end of file