diff --git a/Refit.GeneratorTests/Fixture.cs b/Refit.GeneratorTests/Fixture.cs index 57f4331d7..affae8dab 100644 --- a/Refit.GeneratorTests/Fixture.cs +++ b/Refit.GeneratorTests/Fixture.cs @@ -57,6 +57,46 @@ public interface IGeneratedClient return VerifyGenerator(source); } + public static Task VerifyForType(string declarations) + { + var source = + $$""" + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net.Http; + using System.Text; + using System.Threading; + using System.Threading.Tasks; + using Refit; + + namespace RefitGeneratorTest; + + {{declarations}} + """; + + return VerifyGenerator(source); + } + + public static Task VerifyForDeclaration(string declarations) + { + var source = + $$""" + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net.Http; + using System.Text; + using System.Threading; + using System.Threading.Tasks; + using Refit; + + {{declarations}} + """; + + return VerifyGenerator(source); + } + private static CSharpCompilation CreateLibrary(params string[] source) { var references = new List(); diff --git a/Refit.GeneratorTests/InterfaceTests.cs b/Refit.GeneratorTests/InterfaceTests.cs new file mode 100644 index 000000000..937d7d970 --- /dev/null +++ b/Refit.GeneratorTests/InterfaceTests.cs @@ -0,0 +1,85 @@ +namespace Refit.GeneratorTests; + +public class InterfaceTests +{ + [Fact] + public Task ContainedInterfaceTest() + { + return Fixture.VerifyForType( + """ + public class ContainerType + { + public interface IContainedInterface + { + [Get("/users")] + Task Get(); + } + } + """); + } + + [Fact] + public Task DerivedRefitInterfaceTest() + { + return Fixture.VerifyForType( + """ + public interface IGeneratedInterface : IBaseInterface + { + [Get("/users")] + Task Get(); + } + + public interface IBaseInterface + { + [Get("/posts")] + Task GetPosts(); + } + """); + } + + [Fact] + public Task DerivedNonRefitInterfaceTest() + { + return Fixture.VerifyForType( + """ + public interface IGeneratedInterface : IBaseInterface + { + [Get("/users")] + Task Get(); + } + + public interface IBaseInterface + { + void NonRefitMethod(); + } + """); + } + + [Fact] + public Task NestedNamespaceTest() + { + return Fixture.VerifyForDeclaration( + """ + namespace Nested.RefitGeneratorTest; + + public interface IGeneratedInterface + { + [Get("/users")] + Task Get(); + } + """); + } + + [Fact] + public Task GlobalNamespaceTest() + { + return Fixture.VerifyForDeclaration( + """ + public interface IGeneratedInterface + { + [Get("/users")] + Task Get(); + } + """); + } +} diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#IContainedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#IContainedInterface.g.verified.cs new file mode 100644 index 000000000..b15640c13 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#IContainedInterface.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IContainedInterface.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestContainerTypeIContainedInterface + : global::RefitGeneratorTest.ContainerType.IContainedInterface + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestContainerTypeIContainedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.ContainerType.IContainedInterface.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#IGeneratedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#IGeneratedInterface.g.verified.cs new file mode 100644 index 000000000..437319341 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#IGeneratedInterface.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IGeneratedInterface.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestIGeneratedInterface + : global::RefitGeneratorTest.IGeneratedInterface + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedInterface.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IBaseInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IBaseInterface.g.verified.cs new file mode 100644 index 000000000..1dcf928d5 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IBaseInterface.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IBaseInterface.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestIBaseInterface + : global::RefitGeneratorTest.IBaseInterface + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIBaseInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task GetPosts() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetPosts", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IBaseInterface.GetPosts() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetPosts", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IGeneratedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IGeneratedInterface.g.verified.cs new file mode 100644 index 000000000..c415be964 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IGeneratedInterface.g.verified.cs @@ -0,0 +1,81 @@ +//HintName: IGeneratedInterface.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestIGeneratedInterface + : global::RefitGeneratorTest.IGeneratedInterface + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedInterface.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IBaseInterface.GetPosts() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetPosts", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#IGeneratedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#IGeneratedInterface.g.verified.cs new file mode 100644 index 000000000..d7bc42d86 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#IGeneratedInterface.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IGeneratedInterface.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class IGeneratedInterface + : global::IGeneratedInterface + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public IGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::IGeneratedInterface.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#IGeneratedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#IGeneratedInterface.g.verified.cs new file mode 100644 index 000000000..ae16b03e4 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#IGeneratedInterface.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IGeneratedInterface.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class NestedRefitGeneratorTestIGeneratedInterface + : global::Nested.RefitGeneratorTest.IGeneratedInterface + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public NestedRefitGeneratorTestIGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::Nested.RefitGeneratorTest.IGeneratedInterface.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore