├── .devcontainers ├── Dockerfile ├── devcontainer.json └── post-create.sh ├── .editorconfig ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.yml │ ├── config.yml │ └── feature_request.md ├── renovate.json └── workflows │ ├── ci-build.yml │ ├── lock.yml │ └── release.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── COPYING ├── CodeCoverage.runsettings ├── Directory.Build.props ├── InterfaceStubGenerator.Roslyn38 └── InterfaceStubGenerator.Roslyn38.csproj ├── InterfaceStubGenerator.Roslyn41 └── InterfaceStubGenerator.Roslyn41.csproj ├── InterfaceStubGenerator.Shared ├── DiagnosticDescriptors.cs ├── Emitter.cs ├── ITypeSymbolExtensions.cs ├── ImmutableEquatableArray.cs ├── IncrementalValuesProviderExtensions.cs ├── InterfaceStubGenerator.Shared.projitems ├── InterfaceStubGenerator.Shared.shproj ├── InterfaceStubGenerator.cs ├── IsExternalInit.cs ├── Models │ ├── ContextGenerationModel.cs │ ├── InterfaceModel.cs │ ├── MethodModel.cs │ ├── ParameterModel.cs │ ├── TypeConstraint.cs │ └── WellKnownTypes.cs ├── Parser.cs ├── SourceWriter.cs └── UniqueNameBuilder.cs ├── LICENSE ├── NuGet.config ├── README.md ├── Refit.Benchmarks ├── Benchmarks │ ├── net5.0 │ │ ├── Benchmark_AllReturnTypes.bat │ │ ├── Benchmark_ObservableHttpResponseMessage.bat │ │ ├── Benchmark_Task.bat │ │ ├── Benchmark_TaskApiResponseT.bat │ │ ├── Benchmark_TaskHttpContent.bat │ │ ├── Benchmark_TaskHttpResponseMessage.bat │ │ ├── Benchmark_TaskStream.bat │ │ ├── Benchmark_TaskString.bat │ │ └── Benchmark_TaskT.bat │ ├── net6.0 │ │ ├── Benchmark_AllReturnTypes.bat │ │ ├── Benchmark_ObservableHttpResponseMessage.bat │ │ ├── Benchmark_Task.bat │ │ ├── Benchmark_TaskApiResponseT.bat │ │ ├── Benchmark_TaskHttpContent.bat │ │ ├── Benchmark_TaskHttpResponseMessage.bat │ │ ├── Benchmark_TaskStream.bat │ │ ├── Benchmark_TaskString.bat │ │ └── Benchmark_TaskT.bat │ └── netcoreapp3.1 │ │ ├── Benchmark_AllReturnTypes.bat │ │ ├── Benchmark_ObservableHttpResponseMessage.bat │ │ ├── Benchmark_Task.bat │ │ ├── Benchmark_TaskApiResponseT.bat │ │ ├── Benchmark_TaskHttpContent.bat │ │ ├── Benchmark_TaskHttpResponseMessage.bat │ │ ├── Benchmark_TaskStream.bat │ │ ├── Benchmark_TaskString.bat │ │ └── Benchmark_TaskT.bat ├── EndToEndBenchmark.cs ├── IGitHubService.cs ├── IPerformanceService.cs ├── PerformanceBenchmark.cs ├── Program.cs ├── Refit.Benchmarks.csproj ├── SourceGeneratorBenchmark.cs ├── SourceGeneratorBenchmarksProjects.cs ├── StartupBenchmark.cs ├── StaticFileHttpResponseHandler.cs ├── StaticValueHttpResponseHandler.cs ├── newtonsoft-json-10-users.json └── system-text-json-10-users.json ├── Refit.GeneratorTests ├── Fixture.cs ├── GeneratedTest.cs ├── Incremental │ ├── FunctionTest.cs │ ├── GenericTest.cs │ ├── IncrementalGeneratorRunReasons.cs │ ├── IncrementalTest.cs │ ├── InheritanceTest.cs │ └── TestHelper.cs ├── InterfaceTests.cs ├── MethodTests.cs ├── ModuleInitializer.cs ├── ParameterTests.cs ├── Refit.GeneratorTests.csproj ├── ReturnTypeTests.cs └── _snapshots │ ├── GeneratedTest.ShouldEmitAllFiles#Generated.g.verified.cs │ ├── GeneratedTest.ShouldEmitAllFiles#IGeneratedClient.g.verified.cs │ ├── GeneratedTest.ShouldEmitAllFiles#PreserveAttribute.g.verified.cs │ ├── InterfaceTests.ContainedInterfaceTest#IContainedInterface.g.verified.cs │ ├── InterfaceTests.DefaultInterfaceMethod#IGeneratedInterface.g.verified.cs │ ├── InterfaceTests.DerivedDefaultInterfaceMethod#IBaseInterface.g.verified.cs │ ├── InterfaceTests.DerivedDefaultInterfaceMethod#IGeneratedInterface.g.verified.cs │ ├── InterfaceTests.DisposableTest#IGeneratedInterface.g.verified.cs │ ├── InterfaceTests.GlobalNamespaceTest#IGeneratedInterface.g.verified.cs │ ├── InterfaceTests.InterfaceDerivedFromRefitBaseTest#IBaseInterface.g.verified.cs │ ├── InterfaceTests.InterfaceDerivedFromRefitBaseTest#IDerivedInterface.g.verified.cs │ ├── InterfaceTests.InterfaceWithGenericConstraint#IGeneratedInterface.g.verified.cs │ ├── InterfaceTests.InterfacesWithDifferentCasing#IApi.g.verified.cs │ ├── InterfaceTests.InterfacesWithDifferentCasing#Iapi1.g.verified.cs │ ├── InterfaceTests.InterfacesWithDifferentSignature#IApi.g.verified.cs │ ├── InterfaceTests.InterfacesWithDifferentSignature#IApi1.g.verified.cs │ ├── InterfaceTests.NestedNamespaceTest#IGeneratedInterface.g.verified.cs │ ├── InterfaceTests.NonRefitMethodShouldRaiseDiagnostic#IGeneratedClient.g.verified.cs │ ├── InterfaceTests.NonRefitMethodShouldRaiseDiagnostic.verified.txt │ ├── InterfaceTests.RefitInterfaceDerivedFromBaseTest#IGeneratedInterface.g.verified.cs │ ├── InterfaceTests.RefitInterfaceDerivedFromBaseTest.verified.txt │ ├── InterfaceTests.RefitInterfaceDerivedFromRefitBaseTest#IBaseInterface.g.verified.cs │ ├── InterfaceTests.RefitInterfaceDerivedFromRefitBaseTest#IGeneratedInterface.g.verified.cs │ ├── MethodTests.MethodsWithGenericConstraints#IGeneratedClient.g.verified.cs │ ├── MethodTests.MethodsWithGenericConstraints.verified.txt │ ├── ParameterTests.NullableRouteParameter#IGeneratedClient.g.verified.cs │ ├── ParameterTests.NullableValueTypeRouteParameter#IGeneratedClient.g.verified.cs │ ├── ParameterTests.RouteParameter#IGeneratedClient.g.verified.cs │ ├── ParameterTests.ValueTypeRouteParameter#IGeneratedClient.g.verified.cs │ ├── ReturnTypeTests.GenericConstraintReturnTask#IGeneratedClient.g.verified.cs │ ├── ReturnTypeTests.GenericStructConstraintReturnTask#IGeneratedClient.g.verified.cs │ ├── ReturnTypeTests.GenericTaskShouldWork#IGeneratedClient.g.verified.cs │ ├── ReturnTypeTests.GenericUnmanagedConstraintReturnTask#IGeneratedClient.g.verified.cs │ ├── ReturnTypeTests.ReturnIObservable#IGeneratedClient.g.verified.cs │ ├── ReturnTypeTests.ReturnNullableObject#IGeneratedClient.g.verified.cs │ ├── ReturnTypeTests.ReturnNullableValueType#IGeneratedClient.g.verified.cs │ ├── ReturnTypeTests.ReturnUnsupportedType#IGeneratedClient.g.verified.cs │ └── ReturnTypeTests.VoidTaskShouldWork#IGeneratedClient.g.verified.cs ├── Refit.HttpClientFactory ├── HttpClientFactoryExtensions.cs ├── Refit.HttpClientFactory.csproj └── SettingsFor.cs ├── Refit.Newtonsoft.Json ├── NewtonsoftJsonContentSerializer.cs └── Refit.Newtonsoft.Json.csproj ├── Refit.Tests ├── API │ ├── ApiApprovalTests.Refit.DotNet8_0.verified.txt │ ├── ApiApprovalTests.Refit.DotNet9_0.verified.txt │ ├── ApiApprovalTests.cs │ ├── ApiExtensions.cs │ └── _snapshots │ │ ├── ApiApprovalTests.Refit.DotNet8_0.verified.txt │ │ └── ApiApprovalTests.Refit.DotNet9_0.verified.txt ├── App.config ├── AuthenticatedClientHandlerTests.cs ├── CachedRequestBuilder.cs ├── CamelCaseUrlParameterKeyFormatter.cs ├── DefaultUrlParameterFormatterTest.cs ├── DeliminatorSeparatedPropertyNamesContractResolver.cs ├── DeserializationExceptionFactoryTests.cs ├── ExceptionFactoryTests.cs ├── FormValueMultimapTests.cs ├── GitHubApi.cs ├── GlobalSuppressions.cs ├── HttpClientFactoryExtensionsTests.cs ├── IDefaultInterfaceMethodTests.cs ├── IFooWithOtherAttribute.cs ├── IInterfaceWithoutRefit.cs ├── IServiceWithoutNamespace.cs ├── InheritedGenericInterfacesApi.cs ├── InheritedInterfacesApi.cs ├── InheritedInterfacesInSeparateFileApi.cs ├── IntegrationTestHelper.cs ├── InterfaceStubGenerator.cs ├── MethodOverloads.cs ├── ModuleInitializer.cs ├── ModuleInitializerAttribute.cs ├── MultipartTests.cs ├── MyQueryParams.cs ├── NamespaceCollisionApi.cs ├── NamespaceOverlapApi.cs ├── NamespaceWithGlobalAliasApi.cs ├── NullableReferenceTypes.cs ├── PartialInterfacesApi.First.cs ├── PartialInterfacesApi.Second.cs ├── ReducedUsingInsideNamespaceApi.cs ├── Refit.Tests.csproj ├── RefitSettings.cs ├── ReflectionTests.cs ├── RequestBuilder.cs ├── ResponseTests.cs ├── RestService.cs ├── RestServiceExceptions.cs ├── SerializedContentTests.cs ├── Test Files │ └── Test.pdf ├── TypeCollisionApiA.cs ├── TypeCollisionApiB.cs ├── UniqueNameTests.cs ├── UseCultureAttribute.cs ├── Verifiers │ ├── CSharpIncrementalSourceGeneratorVerifier`1+Test.cs │ ├── CSharpIncrementalSourceGeneratorVerifier`1.cs │ ├── CSharpSourceGeneratorVerifier`1+Test.cs │ ├── CSharpSourceGeneratorVerifier`1.cs │ └── CSharpVerifierHelper.cs ├── XmlContentSerializerTests.cs └── _snapshots │ ├── InterfaceStubGeneratorTests.FindInterfacesSmokeTest#Generated.g.verified.cs │ ├── InterfaceStubGeneratorTests.FindInterfacesSmokeTest#IGitHubApi.g.verified.cs │ ├── InterfaceStubGeneratorTests.FindInterfacesSmokeTest#IGitHubApiDisposable.g.verified.cs │ ├── InterfaceStubGeneratorTests.FindInterfacesSmokeTest#INestedGitHubApi.g.verified.cs │ ├── InterfaceStubGeneratorTests.FindInterfacesSmokeTest#PreserveAttribute.g.verified.cs │ ├── InterfaceStubGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#Generated.g.verified.cs │ ├── InterfaceStubGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#IServiceWithoutNamespace.g.verified.cs │ └── InterfaceStubGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#PreserveAttribute.g.verified.cs ├── Refit.Xml ├── Refit.Xml.csproj └── XmlContentSerializer.cs ├── Refit.sln ├── Refit ├── AnonymousDisposable.cs ├── ApiException.cs ├── ApiResponse.cs ├── Attributes.cs ├── AuthenticatedHttpClientHandler.cs ├── Buffers │ ├── PooledBufferWriter.Stream.NETStandard21.cs │ ├── PooledBufferWriter.Stream.cs │ ├── PooledBufferWriter.ThrowExceptions.cs │ └── PooledBufferWriter.cs ├── CachedRequestBuilderImplementation.cs ├── CamelCaseUrlParameterKeyFormatter.cs ├── CloseGenericMethodKey.cs ├── CollectionFormat.cs ├── DynamicallyAccessedMembersAttribute.cs ├── EnumerableExtensions.cs ├── FormValueMultimap.cs ├── HttpContentExtensions.cs ├── HttpRequestMessageProperties.cs ├── JsonContentSerializer.cs ├── MultipartItem.cs ├── NameValueCollection.cs ├── ProblemDetails.cs ├── Properties │ └── AssemblyInfo.cs ├── PushStreamContent.cs ├── Refit.csproj ├── RefitSettings.cs ├── RequestBuilder.cs ├── RequestBuilderFactory.cs ├── RequestBuilderImplementation.TaskToObservable.cs ├── RequestBuilderImplementation.cs ├── RestMethodInfo.cs ├── RestMethodParameterInfo.cs ├── RestService.cs ├── SystemTextJsonContentSerializer.cs ├── UniqueName.cs ├── ValidationApiException.cs ├── ValueStringBuilder.cs └── targets │ ├── refit.props │ └── refit.targets ├── _config.yml ├── buildtask.snk ├── config ├── filelist.txt └── signclient.json ├── refit_logo.png ├── samples ├── Meow.Common │ ├── Meow.Common.csproj │ ├── Middleware │ │ └── HttpClientDiagnosticsHandler.cs │ ├── Responses │ │ └── SearchResponse.cs │ └── Services │ │ ├── CatsService.cs │ │ └── ITheCatsAPI.cs ├── Meow.sln ├── Meow │ ├── Meow.csproj │ └── Program.cs ├── SampleWithLocalAPIs.sln └── sampleUsngLocalApi │ ├── ConsoleApplication │ ├── ConsoleSampleUsingLocalApi.csproj │ └── Program.cs │ ├── LibraryWithSDKandRefitService │ ├── IRestService.cs │ ├── LibraryWithSDKandRefitService.csproj │ └── ModelForTest.cs │ └── RestApiforTest │ ├── Controllers │ └── ValuesController.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── RestApiForTest.csproj │ ├── Startup.cs │ ├── appsettings.Development.json │ └── appsettings.json ├── stylesheets ├── pygment_trac.css └── styles.css └── version.json /.devcontainers/Dockerfile: -------------------------------------------------------------------------------- 1 | # [Choice] .NET version: 7.0, 7.0-bullseye-slim, 7.0-jammy, 6.0, 6.0-bullseye-slim, 6.0-jammy, 6.0-focal 2 | ARG VARIANT="7.0-jammy" 3 | FROM mcr.microsoft.com/dotnet/sdk:${VARIANT} 4 | 5 | # [Optional] Uncomment this section to install additional OS packages. 6 | # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 7 | # && apt-get -y install --no-install-recommends -------------------------------------------------------------------------------- /.devcontainers/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DevContainer for .NET", 3 | 4 | "build": { 5 | "dockerfile": "./Dockerfile", 6 | "context": ".", 7 | "args": { 8 | // version: 7.0, 7.0-bullseye-slim, 7.0-jammy, 6.0, 6.0-bullseye-slim, 6.0-jammy, 6.0-focal 9 | "VARIANT": "7.0" 10 | } 11 | }, 12 | 13 | "features": { 14 | // GitHub CLI 15 | "ghcr.io/devcontainers/features/github-cli:1": { 16 | "version": "latest" 17 | }, 18 | 19 | // Install common utilities 20 | "ghcr.io/devcontainers/features/common-utils:1": { 21 | "installZsh": true, 22 | "installOhMyZsh": true, 23 | "upgradePackages": true, 24 | "username": "vscode", 25 | "uid": "1000", 26 | "gid": "1000" 27 | } 28 | }, 29 | 30 | "overrideFeatureInstallOrder": [ 31 | "ghcr.io/devcontainers/features/common-utils" 32 | ], 33 | 34 | // Configure tool-specific properties. 35 | "customizations": { 36 | // Configure properties specific to VS Code. 37 | "vscode": { 38 | // Add the IDs of extensions you want installed when the container is created. 39 | "extensions": [ 40 | "ms-dotnettools.csharp", 41 | "ms-vscode.PowerShell", 42 | "VisualStudioExptTeam.vscodeintellicode" 43 | ], 44 | "settings": { 45 | } 46 | } 47 | }, 48 | 49 | // Uncomment if you want to use bash in 'postCreateCommand' after the container is created 50 | "postCreateCommand": "/bin/bash ./.devcontainer/post-create.sh > ~/post-create.log", 51 | 52 | // Uncomment if you want to connect other than 'root'. More info: https://aka.ms/vscode-remote/containers/non-root. 53 | "remoteUser": "vscode" 54 | } 55 | -------------------------------------------------------------------------------- /.devcontainers/post-create.sh: -------------------------------------------------------------------------------- 1 | ## Restore .NET packages and build the default solution 2 | dotnet restore 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | 19 | .idea/ 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Questions 4 | url: https://github.com/reactiveui/refit/discussions 5 | about: 'For general questions about Refit, ask in the GitHub discussions' 6 | - name: Chat 7 | url: https://www.reactiveui.net/slack 8 | about: 'Our slack chat community invite' 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: feature request 6 | assignees: '' 7 | 8 | --- 9 | 10 | 15 | 16 | **Is your feature request related to a problem? Please describe.** 17 | 18 | 19 | 20 | 21 | **Describe the solution you'd like** 22 | 23 | 24 | 25 | 26 | **Describe alternatives you've considered** 27 | 28 | 29 | 30 | 31 | **Describe suggestions on how to achieve the feature** 32 | 33 | 34 | 35 | 36 | **Additional context** 37 | 38 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["local>reactiveui/.github:renovate"] 4 | } -------------------------------------------------------------------------------- /.github/workflows/ci-build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | env: 10 | productNamespacePrefix: "Refit" 11 | 12 | jobs: 13 | build: 14 | uses: reactiveui/actions-common/.github/workflows/workflow-common-setup-and-build.yml@main 15 | with: 16 | productNamespacePrefix: "Refit" 17 | srcFolder: "./" 18 | installWorkflows: true 19 | -------------------------------------------------------------------------------- /.github/workflows/lock.yml: -------------------------------------------------------------------------------- 1 | name: 'Lock Threads' 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | workflow_dispatch: 7 | 8 | permissions: 9 | issues: write 10 | pull-requests: write 11 | 12 | concurrency: 13 | group: lock 14 | 15 | jobs: 16 | action: 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: dessant/lock-threads@v5 20 | with: 21 | github-token: ${{ github.token }} 22 | issue-inactive-days: '14' 23 | pr-inactive-days: '14' 24 | issue-comment: > 25 | This issue has been automatically locked since there 26 | has not been any recent activity after it was closed. 27 | Please open a new issue for related bugs. 28 | pr-comment: > 29 | This pull request has been automatically locked since there 30 | has not been any recent activity after it was closed. 31 | Please open a new issue for related bugs. 32 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | 7 | env: 8 | productNamespacePrefix: "Refit" 9 | 10 | jobs: 11 | release: 12 | uses: reactiveui/actions-common/.github/workflows/workflow-common-release.yml@main 13 | with: 14 | configuration: Release 15 | productNamespacePrefix: "Refit" 16 | srcFolder: "./" 17 | installWorkflows: false 18 | secrets: 19 | SIGN_ACCOUNT_NAME: ${{ secrets.SIGN_ACCOUNT_NAME }} 20 | SIGN_PROFILE_NAME: ${{ secrets.SIGN_PROFILE_NAME }} 21 | AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} 22 | AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} 23 | AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} 24 | NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | 4 | # Folder config file 5 | Desktop.ini 6 | 7 | ## Ignore Visual Studio temporary files, build results, and 8 | ## files generated by popular Visual Studio add-ons. 9 | 10 | # User-specific files 11 | *.suo 12 | *.user 13 | *.userprefs 14 | 15 | .vs/ 16 | 17 | # Build results 18 | bin/[Dd]ebug/ 19 | bin/[Rr]elease/ 20 | *_i.c 21 | *_p.c 22 | *.ilk 23 | *.meta 24 | *.obj 25 | *.pch 26 | bin/**/*.pdb 27 | *.pgc 28 | *.pgd 29 | *.rsp 30 | *.sbr 31 | *.tlb 32 | *.tli 33 | *.tlh 34 | *.tmp 35 | *.vspscc 36 | .builds 37 | 38 | # Idea cache files 39 | 40 | .idea/ 41 | 42 | # Visual C++ cache files 43 | ipch/ 44 | *.aps 45 | *.ncb 46 | *.opensdf 47 | *.sdf 48 | 49 | *.ide/ 50 | 51 | 52 | *.lock.json 53 | *.nuget.props 54 | *.nuget.targets 55 | 56 | # Visual Studio profiler 57 | *.psess 58 | *.vsp 59 | 60 | # ReSharper is a .NET coding add-in 61 | _ReSharper* 62 | 63 | # Click-Once directory 64 | publish 65 | 66 | # Visual Studio Code 67 | 68 | .vscode/ 69 | 70 | # Others 71 | [Bb]in 72 | [Oo]bj 73 | sql 74 | TestResults 75 | *.Cache 76 | ClientBin 77 | stylecop.* 78 | ~$* 79 | *.dbmdl 80 | .DS_Store 81 | Generated_Code #added for RIA/Silverlight projects 82 | 83 | # Custom 84 | 85 | # packages 86 | Release/ 87 | packages/ 88 | 89 | *.userprefs 90 | Refit-Tests/test-results 91 | /InterfaceStubGenerator.App/Properties/launchSettings.json 92 | *.binlog 93 | /InterfaceStubGenerator.Core/Properties/launchSettings.json 94 | *.svclog 95 | **/BenchmarkDotNet.Artifacts 96 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of 4 | fostering an open and welcoming community, we pledge to respect all people who 5 | contribute through reporting issues, posting feature requests, updating 6 | documentation, submitting pull requests or patches, and other activities. 7 | 8 | We are committed to making participation in this project a harassment-free 9 | experience for everyone, regardless of level of experience, gender, gender 10 | identity and expression, sexual orientation, disability, personal appearance, 11 | body size, race, ethnicity, age, religion, or nationality. 12 | 13 | Examples of unacceptable behavior by participants include: 14 | 15 | * The use of sexualized language or imagery 16 | * Personal attacks 17 | * Trolling or insulting/derogatory comments 18 | * Public or private harassment 19 | * Publishing other's private information, such as physical or electronic 20 | addresses, without explicit permission 21 | * Other unethical or unprofessional conduct 22 | 23 | Project maintainers have the right and responsibility to remove, edit, or 24 | reject comments, commits, code, wiki edits, issues, and other contributions 25 | that are not aligned to this Code of Conduct, or to ban temporarily or 26 | permanently any contributor for other behaviors that they deem inappropriate, 27 | threatening, offensive, or harmful. 28 | 29 | By adopting this Code of Conduct, project maintainers commit themselves to 30 | fairly and consistently applying these principles to every aspect of managing 31 | this project. Project maintainers who do not follow or enforce the Code of 32 | Conduct may be permanently removed from the project team. 33 | 34 | This Code of Conduct applies both within project spaces and in public spaces 35 | when an individual is representing the project or its community. 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 38 | reported by contacting a project maintainer at anais@anaisbetts.org. All 39 | complaints will be reviewed and investigated and will result in a response that 40 | is deemed necessary and appropriate to the circumstances. Maintainers are 41 | obligated to maintain confidentiality with regard to the reporter of an 42 | incident. 43 | 44 | 45 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 46 | version 1.3.0, available at 47 | [http://contributor-covenant.org/version/1/3/0/][version] 48 | 49 | [homepage]: http://contributor-covenant.org 50 | [version]: http://contributor-covenant.org/version/1/3/0/ 51 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 GitHub 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /CodeCoverage.runsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | cobertura 9 | [xunit.*]*,[*Tests]*,[System.*]*,[InterfaceStubGenerator.App]* 10 | Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Roslyn38/InterfaceStubGenerator.Roslyn38.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | InterfaceStubGeneratorV1 6 | Refit.Generator 7 | false 8 | ..\buildtask.snk 9 | true 10 | true 11 | enable 12 | 3.8.0 13 | true 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | $(BuildVersion) 23 | $(BuildVersionSimple) 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Roslyn41/InterfaceStubGenerator.Roslyn41.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | InterfaceStubGeneratorV2 6 | Refit.Generator 7 | false 8 | ..\buildtask.snk 9 | true 10 | true 11 | enable 12 | $(DefineConstants);ROSLYN_4 13 | 4.1.0 14 | true 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | $(BuildVersion) 24 | $(BuildVersionSimple) 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Shared/DiagnosticDescriptors.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | 3 | namespace Refit.Generator; 4 | 5 | internal static class DiagnosticDescriptors 6 | { 7 | #pragma warning disable RS2008 // Enable analyzer release tracking 8 | public static readonly DiagnosticDescriptor InvalidRefitMember = 9 | new( 10 | "RF001", 11 | "Refit types must have Refit HTTP method attributes", 12 | "Method {0}.{1} either has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument", 13 | "Refit", 14 | DiagnosticSeverity.Warning, 15 | true 16 | ); 17 | 18 | public static readonly DiagnosticDescriptor RefitNotReferenced = 19 | new( 20 | "RF002", 21 | "Refit must be referenced", 22 | "Refit is not referenced. Add a reference to Refit.", 23 | "Refit", 24 | DiagnosticSeverity.Error, 25 | true 26 | ); 27 | #pragma warning restore RS2008 // Enable analyzer release tracking 28 | } 29 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Shared/ITypeSymbolExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.CodeAnalysis; 6 | 7 | namespace Refit.Generator 8 | { 9 | static class ITypeSymbolExtensions 10 | { 11 | public static IEnumerable GetBaseTypesAndThis(this ITypeSymbol? type) 12 | { 13 | var current = type; 14 | while (current != null) 15 | { 16 | yield return current; 17 | current = current.BaseType; 18 | } 19 | } 20 | 21 | // Determine if "type" inherits from "baseType", ignoring constructed types, optionally including interfaces, 22 | // dealing only with original types. 23 | public static bool InheritsFromOrEquals( 24 | this ITypeSymbol type, 25 | ITypeSymbol baseType, 26 | bool includeInterfaces 27 | ) 28 | { 29 | if (!includeInterfaces) 30 | { 31 | return InheritsFromOrEquals(type, baseType); 32 | } 33 | 34 | return type.GetBaseTypesAndThis() 35 | .Concat(type.AllInterfaces) 36 | .Any(t => t.Equals(baseType, SymbolEqualityComparer.Default)); 37 | } 38 | 39 | // Determine if "type" inherits from "baseType", ignoring constructed types and interfaces, dealing 40 | // only with original types. 41 | public static bool InheritsFromOrEquals(this ITypeSymbol type, ITypeSymbol baseType) 42 | { 43 | return type.GetBaseTypesAndThis() 44 | .Any(t => t.Equals(baseType, SymbolEqualityComparer.Default)); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Shared/InterfaceStubGenerator.Shared.projitems: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | b591423d-f92d-4e00-b0eb-615c9853506c 7 | 8 | 9 | InterfaceStubGenerator.Shared 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Shared/InterfaceStubGenerator.Shared.shproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | b591423d-f92d-4e00-b0eb-615c9853506c 5 | 14.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Shared/IsExternalInit.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | #if NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0 || NETCOREAPP3_1 || NET45 || NET451 || NET452 || NET6 || NET461 || NET462 || NET47 || NET471 || NET472 || NET48 6 | 7 | using System.ComponentModel; 8 | 9 | // ReSharper disable once CheckNamespace 10 | namespace System.Runtime.CompilerServices 11 | { 12 | /// 13 | /// Reserved to be used by the compiler for tracking metadata. 14 | /// This class should not be used by developers in source code. 15 | /// 16 | [EditorBrowsable(EditorBrowsableState.Never)] 17 | internal static class IsExternalInit { } 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Shared/Models/ContextGenerationModel.cs: -------------------------------------------------------------------------------- 1 | namespace Refit.Generator; 2 | 3 | internal sealed record ContextGenerationModel( 4 | string RefitInternalNamespace, 5 | string PreserveAttributeDisplayName, 6 | ImmutableEquatableArray Interfaces 7 | ); 8 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Shared/Models/InterfaceModel.cs: -------------------------------------------------------------------------------- 1 | namespace Refit.Generator; 2 | 3 | internal sealed record InterfaceModel( 4 | string PreserveAttributeDisplayName, 5 | string FileName, 6 | string ClassName, 7 | string Ns, 8 | string ClassDeclaration, 9 | string InterfaceDisplayName, 10 | string ClassSuffix, 11 | ImmutableEquatableArray Constraints, 12 | ImmutableEquatableArray MemberNames, 13 | ImmutableEquatableArray NonRefitMethods, 14 | ImmutableEquatableArray RefitMethods, 15 | ImmutableEquatableArray DerivedRefitMethods, 16 | Nullability Nullability, 17 | bool DisposeMethod 18 | ); 19 | 20 | internal enum Nullability : byte 21 | { 22 | Enabled, 23 | Disabled, 24 | None 25 | } 26 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Shared/Models/MethodModel.cs: -------------------------------------------------------------------------------- 1 | namespace Refit.Generator; 2 | 3 | internal sealed record MethodModel( 4 | string Name, 5 | string ReturnType, 6 | string ContainingType, 7 | string DeclaredMethod, 8 | ReturnTypeInfo ReturnTypeMetadata, 9 | ImmutableEquatableArray Parameters, 10 | ImmutableEquatableArray Constraints 11 | ); 12 | 13 | internal enum ReturnTypeInfo : byte 14 | { 15 | Return, 16 | AsyncVoid, 17 | AsyncResult 18 | } 19 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Shared/Models/ParameterModel.cs: -------------------------------------------------------------------------------- 1 | namespace Refit.Generator; 2 | 3 | internal sealed record ParameterModel( 4 | string MetadataName, 5 | string Type, 6 | bool Annotation, 7 | bool IsGeneric 8 | ); 9 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Shared/Models/TypeConstraint.cs: -------------------------------------------------------------------------------- 1 | namespace Refit.Generator; 2 | 3 | internal readonly record struct TypeConstraint( 4 | string TypeName, 5 | string DeclaredName, 6 | KnownTypeConstraint KnownTypeConstraint, 7 | ImmutableEquatableArray Constraints 8 | ); 9 | 10 | [Flags] 11 | internal enum KnownTypeConstraint : byte 12 | { 13 | None = 0, 14 | Class = 1 << 0, 15 | Unmanaged = 1 << 1, 16 | Struct = 1 << 2, 17 | NotNull = 1 << 3, 18 | New = 1 << 4 19 | } 20 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Shared/Models/WellKnownTypes.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | 3 | namespace Refit.Generator; 4 | 5 | public class WellKnownTypes(Compilation compilation) 6 | { 7 | readonly Dictionary cachedTypes = new(); 8 | 9 | public INamedTypeSymbol Get() => Get(typeof(T)); 10 | public INamedTypeSymbol Get(Type type) 11 | { 12 | return Get(type.FullName ?? throw new InvalidOperationException("Could not get name of type " + type)); 13 | } 14 | 15 | public INamedTypeSymbol? TryGet(string typeFullName) 16 | { 17 | if (cachedTypes.TryGetValue(typeFullName, out var typeSymbol)) 18 | { 19 | return typeSymbol; 20 | } 21 | 22 | typeSymbol = compilation.GetTypeByMetadataName(typeFullName); 23 | cachedTypes.Add(typeFullName, typeSymbol); 24 | 25 | return typeSymbol; 26 | } 27 | 28 | INamedTypeSymbol Get(string typeFullName) => 29 | TryGet(typeFullName) ?? throw new InvalidOperationException("Could not get type " + typeFullName); 30 | } 31 | -------------------------------------------------------------------------------- /InterfaceStubGenerator.Shared/UniqueNameBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace Refit.Generator; 2 | 3 | // 4 | // UniqueNameBuilder. 5 | // 6 | public class UniqueNameBuilder() 7 | { 8 | private readonly HashSet _usedNames = new(StringComparer.Ordinal); 9 | private readonly UniqueNameBuilder? _parentScope; 10 | 11 | private UniqueNameBuilder(UniqueNameBuilder parentScope) 12 | : this() 13 | { 14 | _parentScope = parentScope; 15 | } 16 | 17 | /// 18 | /// Reserve a name. 19 | /// 20 | /// 21 | public void Reserve(string name) => _usedNames.Add(name); 22 | 23 | /// 24 | /// Create a new scope. 25 | /// 26 | /// Unique Name Builder. 27 | public UniqueNameBuilder NewScope() => new(this); 28 | 29 | /// 30 | /// Generate a unique name. 31 | /// 32 | /// THe name. 33 | /// 34 | public string New(string name) 35 | { 36 | var i = 0; 37 | var uniqueName = name; 38 | while (Contains(uniqueName)) 39 | { 40 | uniqueName = name + i; 41 | i++; 42 | } 43 | 44 | _usedNames.Add(uniqueName); 45 | 46 | return uniqueName; 47 | } 48 | 49 | /// 50 | /// Reserve names. 51 | /// 52 | /// The name. 53 | public void Reserve(IEnumerable names) 54 | { 55 | if (names == null) 56 | { 57 | return; 58 | } 59 | 60 | foreach (var name in names) 61 | { 62 | _usedNames.Add(name); 63 | } 64 | } 65 | 66 | private bool Contains(string name) 67 | { 68 | if (_usedNames.Contains(name)) 69 | return true; 70 | 71 | if (_parentScope != null) 72 | return _parentScope.Contains(name); 73 | 74 | return false; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) ReactiveUI 2012 - 2025 4 | 5 | All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /NuGet.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net5.0/Benchmark_AllReturnTypes.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net5.0/Benchmark_ObservableHttpResponseMessage.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *ObservableHttpResponseMessage* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net5.0/Benchmark_Task.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *Task_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net5.0/Benchmark_TaskApiResponseT.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskApiResponseT_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net5.0/Benchmark_TaskHttpContent.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskHttpContent_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net5.0/Benchmark_TaskHttpResponseMessage.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskHttpResponseMessage_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net5.0/Benchmark_TaskStream.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskStream_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net5.0/Benchmark_TaskString.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskString_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net5.0/Benchmark_TaskT.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskT_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net6.0/Benchmark_AllReturnTypes.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net6.0/Benchmark_ObservableHttpResponseMessage.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *ObservableHttpResponseMessage* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net6.0/Benchmark_Task.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *Task_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net6.0/Benchmark_TaskApiResponseT.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskApiResponseT_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net6.0/Benchmark_TaskHttpContent.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskHttpContent_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net6.0/Benchmark_TaskHttpResponseMessage.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskHttpResponseMessage_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net6.0/Benchmark_TaskStream.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskStream_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net6.0/Benchmark_TaskString.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskString_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/net6.0/Benchmark_TaskT.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskT_Async* --framework=net6.0 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/netcoreapp3.1/Benchmark_AllReturnTypes.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --framework=netcoreapp3.1 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/netcoreapp3.1/Benchmark_ObservableHttpResponseMessage.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *ObservableHttpResponseMessage* --framework=netcoreapp3.1 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/netcoreapp3.1/Benchmark_Task.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *Task_Async* --framework=netcoreapp3.1 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/netcoreapp3.1/Benchmark_TaskApiResponseT.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskApiResponseT_Async* --framework=netcoreapp3.1 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/netcoreapp3.1/Benchmark_TaskHttpContent.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskHttpContent_Async* --framework=netcoreapp3.1 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/netcoreapp3.1/Benchmark_TaskHttpResponseMessage.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskHttpResponseMessage_Async* --framework=netcoreapp3.1 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/netcoreapp3.1/Benchmark_TaskStream.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskStream_Async* --framework=netcoreapp3.1 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/netcoreapp3.1/Benchmark_TaskString.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskString_Async* --framework=netcoreapp3.1 -------------------------------------------------------------------------------- /Refit.Benchmarks/Benchmarks/netcoreapp3.1/Benchmark_TaskT.bat: -------------------------------------------------------------------------------- 1 | dotnet run --project ../../Refit.Benchmarks.csproj -c Release --filter *TaskT_Async* --framework=netcoreapp3.1 -------------------------------------------------------------------------------- /Refit.Benchmarks/IGitHubService.cs: -------------------------------------------------------------------------------- 1 | namespace Refit.Benchmarks; 2 | 3 | public interface IGitHubService 4 | { 5 | //Task - throws 6 | [Get("/users")] 7 | public Task GetUsersTaskAsync(); 8 | 9 | [Post("/users")] 10 | public Task PostUsersTaskAsync([Body] IEnumerable users); 11 | 12 | //Task - throws 13 | [Get("/users")] 14 | public Task GetUsersTaskStringAsync(); 15 | 16 | [Post("/users")] 17 | public Task PostUsersTaskStringAsync([Body] IEnumerable users); 18 | 19 | //Task - throws 20 | [Get("/users")] 21 | public Task GetUsersTaskStreamAsync(); 22 | 23 | [Post("/users")] 24 | public Task PostUsersTaskStreamAsync([Body] IEnumerable users); 25 | 26 | //Task - throws 27 | [Get("/users")] 28 | public Task GetUsersTaskHttpContentAsync(); 29 | 30 | [Post("/users")] 31 | public Task PostUsersTaskHttpContentAsync([Body] IEnumerable users); 32 | 33 | //Task 34 | [Get("/users")] 35 | public Task GetUsersTaskHttpResponseMessageAsync(); 36 | 37 | [Post("/users")] 38 | public Task PostUsersTaskHttpResponseMessageAsync( 39 | [Body] IEnumerable users 40 | ); 41 | 42 | //IObservable 43 | [Get("/users")] 44 | public IObservable GetUsersObservableHttpResponseMessage(); 45 | 46 | [Post("/users")] 47 | public IObservable PostUsersObservableHttpResponseMessage( 48 | [Body] IEnumerable users 49 | ); 50 | 51 | //Task<> - throws 52 | [Get("/users")] 53 | public Task> GetUsersTaskTAsync(); 54 | 55 | [Post("/users")] 56 | public Task> PostUsersTaskTAsync([Body] IEnumerable users); 57 | 58 | //Task> 59 | [Get("/users")] 60 | public Task>> GetUsersTaskApiResponseTAsync(); 61 | 62 | [Post("/users")] 63 | public Task>> PostUsersTaskApiResponseTAsync( 64 | [Body] IEnumerable users 65 | ); 66 | } 67 | 68 | public class User 69 | { 70 | public int Id { get; set; } 71 | public string Name { get; set; } 72 | public string Bio { get; set; } 73 | public int Followers { get; set; } 74 | public int Following { get; set; } 75 | public string Url { get; set; } 76 | } -------------------------------------------------------------------------------- /Refit.Benchmarks/IPerformanceService.cs: -------------------------------------------------------------------------------- 1 | namespace Refit.Benchmarks; 2 | 3 | public interface IPerformanceService 4 | { 5 | [Get("/users")] 6 | public Task ConstantRoute(); 7 | 8 | [Get("/users/{id}")] 9 | public Task DynamicRoute(int id); 10 | 11 | [Get("/users/{id}/{user}/{status}")] 12 | public Task ComplexDynamicRoute(int id, string user, string status); 13 | 14 | [Get("/users/{request.someProperty}")] 15 | public Task ObjectRequest(PathBoundObject request); 16 | 17 | [Post("/users/{id}/{request.someProperty}")] 18 | [Headers("User-Agent: Awesome Octocat App", "X-Emoji: :smile_cat:")] 19 | public Task ComplexRequest(int id, PathBoundObject request, [Query(CollectionFormat.Multi)]int[] queries); 20 | } 21 | 22 | public class PathBoundObject 23 | { 24 | public string SomeProperty { get; set; } 25 | 26 | [Query] 27 | public string SomeQuery { get; set; } 28 | } 29 | -------------------------------------------------------------------------------- /Refit.Benchmarks/PerformanceBenchmark.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using BenchmarkDotNet.Attributes; 3 | 4 | namespace Refit.Benchmarks; 5 | 6 | [MemoryDiagnoser] 7 | public class PerformanceBenchmark 8 | { 9 | private IPerformanceService? service; 10 | 11 | private const string Host = "https://github.com"; 12 | private SystemTextJsonContentSerializer systemTextJsonContentSerializer; 13 | 14 | [GlobalSetup] 15 | public Task SetupAsync() 16 | { 17 | systemTextJsonContentSerializer = new SystemTextJsonContentSerializer(); 18 | service = 19 | RestService.For( 20 | Host, 21 | new RefitSettings(systemTextJsonContentSerializer) 22 | { 23 | HttpMessageHandlerFactory = () => 24 | new StaticValueHttpResponseHandler( 25 | "Ok", 26 | HttpStatusCode.OK 27 | ) 28 | } 29 | ); 30 | 31 | return Task.CompletedTask; 32 | } 33 | 34 | [Benchmark] 35 | public async Task ConstantRouteAsync() => await service.ConstantRoute(); 36 | 37 | [Benchmark] 38 | public async Task DynamicRouteAsync() => await service.DynamicRoute(101); 39 | 40 | [Benchmark] 41 | public async Task ComplexDynamicRouteAsync() => await service.ComplexDynamicRoute(101, "tom", "yCxv"); 42 | 43 | [Benchmark] 44 | public async Task ObjectRequestAsync() => await service.ObjectRequest(new PathBoundObject(){SomeProperty = "myProperty", SomeQuery = "myQuery"}); 45 | 46 | [Benchmark] 47 | public async Task ComplexRequestAsync() => await service.ComplexRequest(101, new PathBoundObject(){SomeProperty = "myProperty", SomeQuery = "myQuery"}, [1,2,3,4,5,6]); 48 | } 49 | -------------------------------------------------------------------------------- /Refit.Benchmarks/Program.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Running; 2 | using Refit.Benchmarks; 3 | 4 | if (args is { Length: > 0 }) 5 | { 6 | BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); 7 | } 8 | else 9 | { 10 | BenchmarkRunner.Run(); 11 | // BenchmarkRunner.Run(); 12 | // BenchmarkRunner.Run(); 13 | // BenchmarkRunner.Run(); 14 | } 15 | -------------------------------------------------------------------------------- /Refit.Benchmarks/Refit.Benchmarks.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Exe 7 | net8.0 8 | false 9 | $(NoWarn);CS1591 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | PreserveNewest 32 | 33 | 34 | 35 | PreserveNewest 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Refit.Benchmarks/StartupBenchmark.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using BenchmarkDotNet.Attributes; 3 | 4 | namespace Refit.Benchmarks; 5 | 6 | [MemoryDiagnoser] 7 | public class StartupBenchmark 8 | { 9 | private IPerformanceService initialisedService; 10 | private const string Host = "https://github.com"; 11 | private readonly RefitSettings settings = new RefitSettings() 12 | { 13 | HttpMessageHandlerFactory = () => 14 | new StaticValueHttpResponseHandler( 15 | "Ok", 16 | HttpStatusCode.OK 17 | ) 18 | }; 19 | 20 | 21 | [IterationSetup(Targets = [nameof(FirstCallConstantRouteAsync), nameof(FirstCallComplexRequestAsync)])] 22 | public void Setup() 23 | { 24 | initialisedService = RestService.For(Host, settings); 25 | } 26 | 27 | [Benchmark] 28 | public IPerformanceService CreateService() => RestService.For(Host, settings); 29 | 30 | [Benchmark] 31 | public async Task FirstCallConstantRouteAsync() => await initialisedService.ConstantRoute(); 32 | 33 | [Benchmark] 34 | public async Task ConstantRouteAsync() 35 | { 36 | var service = RestService.For(Host, settings); 37 | return await service.ConstantRoute(); 38 | } 39 | 40 | [Benchmark] 41 | public async Task FirstCallComplexRequestAsync() => await initialisedService.ObjectRequest(new PathBoundObject(){SomeProperty = "myProperty", SomeQuery = "myQuery"}); 42 | 43 | [Benchmark] 44 | public async Task ComplexRequestAsync() 45 | { 46 | var service = RestService.For(Host, settings); 47 | return await service.ObjectRequest(new PathBoundObject(){SomeProperty = "myProperty", SomeQuery = "myQuery"}); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Refit.Benchmarks/StaticFileHttpResponseHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace Refit.Benchmarks; 4 | 5 | public class StaticFileHttpResponseHandler : HttpMessageHandler 6 | { 7 | private readonly HttpStatusCode responseCode; 8 | private readonly string responsePayload; 9 | 10 | public StaticFileHttpResponseHandler(string fileName, HttpStatusCode responseCode) 11 | { 12 | if (string.IsNullOrEmpty(fileName)) 13 | throw new ArgumentNullException(nameof(fileName)); 14 | 15 | responsePayload = File.ReadAllText(fileName); 16 | ; 17 | this.responseCode = responseCode; 18 | } 19 | 20 | protected override Task SendAsync( 21 | HttpRequestMessage request, 22 | CancellationToken cancellationToken 23 | ) 24 | { 25 | return Task.FromResult( 26 | new HttpResponseMessage(responseCode) 27 | { 28 | RequestMessage = request, 29 | Content = new StringContent(responsePayload) 30 | } 31 | ); 32 | } 33 | } -------------------------------------------------------------------------------- /Refit.Benchmarks/StaticValueHttpResponseHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace Refit.Benchmarks; 4 | 5 | public class StaticValueHttpResponseHandler (string response, HttpStatusCode code) : HttpMessageHandler 6 | { 7 | protected override Task SendAsync( 8 | HttpRequestMessage request, 9 | CancellationToken cancellationToken 10 | ) 11 | { 12 | return Task.FromResult( 13 | new HttpResponseMessage(code) 14 | { 15 | RequestMessage = request, 16 | Content = new StringContent(response) 17 | } 18 | ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/GeneratedTest.cs: -------------------------------------------------------------------------------- 1 | namespace Refit.GeneratorTests; 2 | 3 | public class GeneratedTest 4 | { 5 | [Fact] 6 | public Task ShouldEmitAllFiles() 7 | { 8 | return Fixture.VerifyForBody( 9 | """ 10 | [Get("/users")] 11 | Task Get(); 12 | """, false); 13 | } 14 | 15 | [Fact] 16 | public Task ShouldNotEmitFilesWhenNoRefitInterfaces() 17 | { 18 | // Refit should not generate any code when no valid Refit interfaces are present. 19 | return Fixture.VerifyForBody("", false); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/Incremental/IncrementalGeneratorRunReasons.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | 3 | namespace Refit.GeneratorTests.Incremental; 4 | 5 | internal record IncrementalGeneratorRunReasons( 6 | IncrementalStepRunReason BuildRefitStep, 7 | IncrementalStepRunReason ReportDiagnosticsStep 8 | ) 9 | { 10 | public static readonly IncrementalGeneratorRunReasons New = 11 | new(IncrementalStepRunReason.New, IncrementalStepRunReason.New); 12 | 13 | public static readonly IncrementalGeneratorRunReasons Cached = 14 | new( 15 | // compilation step should always be modified as each time a new compilation is passed 16 | IncrementalStepRunReason.Cached, 17 | IncrementalStepRunReason.Unchanged 18 | ); 19 | 20 | public static readonly IncrementalGeneratorRunReasons Modified = Cached with 21 | { 22 | ReportDiagnosticsStep = IncrementalStepRunReason.Modified, 23 | BuildRefitStep = IncrementalStepRunReason.Modified, 24 | }; 25 | 26 | public static readonly IncrementalGeneratorRunReasons ModifiedSource = Cached with 27 | { 28 | ReportDiagnosticsStep = IncrementalStepRunReason.Unchanged, 29 | BuildRefitStep = IncrementalStepRunReason.Modified, 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/MethodTests.cs: -------------------------------------------------------------------------------- 1 | namespace Refit.GeneratorTests; 2 | 3 | public class MethodTests 4 | { 5 | [Fact] 6 | public Task MethodsWithGenericConstraints() 7 | { 8 | return Fixture.VerifyForBody( 9 | """ 10 | [Get("/users")] 11 | Task Get() 12 | where T1 : class 13 | where T2 : unmanaged 14 | where T3 : struct 15 | where T4 : notnull 16 | where T5 : class, IDisposable, new(); 17 | 18 | void NonRefitMethod() 19 | where T1 : class 20 | where T2 : unmanaged 21 | where T3 : struct 22 | where T4 : notnull 23 | where T5 : class, IDisposable, new(); 24 | """); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/ModuleInitializer.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | using VerifyTests.DiffPlex; 3 | 4 | namespace Refit.GeneratorTests; 5 | 6 | public static class ModuleInitializer 7 | { 8 | // ModuleInitializer should only be used in apps 9 | #pragma warning disable CA2255 10 | [ModuleInitializer] 11 | #pragma warning restore CA2255 12 | public static void Init() 13 | { 14 | DerivePathInfo((file, _, type, method) => new(Path.Combine(Path.GetDirectoryName(file), "_snapshots"), type.Name, method.Name)); 15 | 16 | VerifySourceGenerators.Initialize(); 17 | VerifyDiffPlex.Initialize(OutputType.Compact); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/ParameterTests.cs: -------------------------------------------------------------------------------- 1 | namespace Refit.GeneratorTests; 2 | 3 | public class ParameterTests 4 | { 5 | [Fact] 6 | public Task RouteParameter() 7 | { 8 | return Fixture.VerifyForBody( 9 | """ 10 | [Get("/users/{user}")] 11 | Task Get(string user); 12 | """); 13 | } 14 | 15 | [Fact] 16 | public Task NullableRouteParameter() 17 | { 18 | return Fixture.VerifyForBody( 19 | """ 20 | [Get("/users/{user}")] 21 | Task Get(string? user); 22 | """); 23 | } 24 | 25 | [Fact] 26 | public Task ValueTypeRouteParameter() 27 | { 28 | return Fixture.VerifyForBody( 29 | """ 30 | [Get("/users/{user}")] 31 | Task Get(int user); 32 | """); 33 | } 34 | 35 | [Fact] 36 | public Task NullableValueTypeRouteParameter() 37 | { 38 | return Fixture.VerifyForBody( 39 | """ 40 | [Get("/users/{user}")] 41 | Task Get(int? user); 42 | """); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/ReturnTypeTests.cs: -------------------------------------------------------------------------------- 1 | namespace Refit.GeneratorTests; 2 | 3 | public class ReturnTypeTests 4 | { 5 | [Fact] 6 | public Task GenericTaskShouldWork() 7 | { 8 | return Fixture.VerifyForBody( 9 | """ 10 | [Get("/users")] 11 | Task Get(); 12 | """); 13 | } 14 | 15 | [Fact] 16 | public Task ReturnNullableObject() 17 | { 18 | return Fixture.VerifyForBody( 19 | """ 20 | [Get("/users")] 21 | Task Get(); 22 | """); 23 | } 24 | 25 | [Fact] 26 | public Task ReturnNullableValueType() 27 | { 28 | return Fixture.VerifyForBody( 29 | """ 30 | [Get("/users")] 31 | Task Get(); 32 | """); 33 | } 34 | 35 | [Fact] 36 | public Task VoidTaskShouldWork() 37 | { 38 | return Fixture.VerifyForBody( 39 | """ 40 | [Post("/users")] 41 | Task Post(); 42 | """); 43 | } 44 | 45 | [Fact] 46 | public Task GenericConstraintReturnTask() 47 | { 48 | return Fixture.VerifyForBody( 49 | """ 50 | [Get("/users")] 51 | Task Get() where T : class, IDisposable, new(); 52 | """); 53 | } 54 | 55 | [Fact] 56 | public Task GenericUnmanagedConstraintReturnTask() 57 | { 58 | return Fixture.VerifyForBody( 59 | """ 60 | [Get("/users")] 61 | Task Get() where T : unmanaged; 62 | """); 63 | } 64 | 65 | [Fact] 66 | public Task GenericStructConstraintReturnTask() 67 | { 68 | return Fixture.VerifyForBody( 69 | """ 70 | [Get("/users")] 71 | Task Get() where T : struct 72 | """); 73 | } 74 | 75 | [Fact] 76 | public Task ReturnIObservable() 77 | { 78 | return Fixture.VerifyForBody( 79 | """ 80 | [Get("/users/{user}")] 81 | IObservable GetUser(string user); 82 | """); 83 | } 84 | 85 | [Fact] 86 | public Task ReturnUnsupportedType() 87 | { 88 | return Fixture.VerifyForBody( 89 | """ 90 | [Get("/users/{user}")] 91 | string GetUser(string user); 92 | """); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#Generated.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: Generated.g.cs 2 | 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | /// 8 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 9 | [global::System.Diagnostics.DebuggerNonUserCode] 10 | [global::RefitInternalGenerated.PreserveAttribute] 11 | [global::System.Reflection.Obfuscation(Exclude=true)] 12 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 13 | internal static partial class Generated 14 | { 15 | #if NET5_0_OR_GREATER 16 | [System.Runtime.CompilerServices.ModuleInitializer] 17 | [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] 18 | public static void Initialize() 19 | { 20 | } 21 | #endif 22 | } 23 | } 24 | #pragma warning restore 25 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#IGeneratedClient.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedClient.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedClient 17 | : global::RefitGeneratorTest.IGeneratedClient 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#PreserveAttribute.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: PreserveAttribute.g.cs 2 | 3 | #pragma warning disable 4 | namespace RefitInternalGenerated 5 | { 6 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 7 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 8 | [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)] 9 | sealed class PreserveAttribute : global::System.Attribute 10 | { 11 | // 12 | // Fields 13 | // 14 | public bool AllMembers; 15 | 16 | public bool Conditional; 17 | } 18 | } 19 | #pragma warning restore 20 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#IContainedInterface.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IContainedInterface.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestContainerTypeIContainedInterface 17 | : global::RefitGeneratorTest.ContainerType.IContainedInterface 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestContainerTypeIContainedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.ContainerType.IContainedInterface.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.DefaultInterfaceMethod#IGeneratedInterface.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedInterface.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedInterface 17 | : global::RefitGeneratorTest.IGeneratedInterface 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedInterface.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedDefaultInterfaceMethod#IBaseInterface.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IBaseInterface.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIBaseInterface 17 | : global::RefitGeneratorTest.IBaseInterface 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIBaseInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task GetPosts() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("GetPosts", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IBaseInterface.GetPosts() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("GetPosts", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.DisposableTest#IGeneratedInterface.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedInterface.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class IGeneratedInterface 17 | : global::IGeneratedInterface 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public IGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::IGeneratedInterface.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | 49 | /// 50 | void global::System.IDisposable.Dispose() 51 | { 52 | Client?.Dispose(); 53 | } 54 | } 55 | } 56 | } 57 | 58 | #pragma warning restore 59 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#IGeneratedInterface.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedInterface.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class IGeneratedInterface 17 | : global::IGeneratedInterface 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public IGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::IGeneratedInterface.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.InterfaceDerivedFromRefitBaseTest#IBaseInterface.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IBaseInterface.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIBaseInterface 17 | : global::RefitGeneratorTest.IBaseInterface 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIBaseInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IBaseInterface.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.InterfaceDerivedFromRefitBaseTest#IDerivedInterface.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IDerivedInterface.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIDerivedInterface 17 | : global::RefitGeneratorTest.IDerivedInterface 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIDerivedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IBaseInterface.Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | } 40 | } 41 | } 42 | 43 | #pragma warning restore 44 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.InterfaceWithGenericConstraint#IGeneratedInterface.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedInterface.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class IGeneratedInterface 17 | : global::IGeneratedInterface 18 | where T1 : class 19 | where T2 : unmanaged 20 | where T3 : struct 21 | where T4 : notnull 22 | where T5 : class, global::System.IDisposable, new() 23 | { 24 | /// 25 | public global::System.Net.Http.HttpClient Client { get; } 26 | readonly global::Refit.IRequestBuilder requestBuilder; 27 | 28 | /// 29 | public IGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 30 | { 31 | Client = client; 32 | this.requestBuilder = requestBuilder; 33 | } 34 | 35 | 36 | /// 37 | public async global::System.Threading.Tasks.Task Get() 38 | { 39 | var ______arguments = global::System.Array.Empty(); 40 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 41 | 42 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 43 | } 44 | 45 | /// 46 | async global::System.Threading.Tasks.Task global::IGeneratedInterface.Get() 47 | { 48 | var ______arguments = global::System.Array.Empty(); 49 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 50 | 51 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 52 | } 53 | } 54 | } 55 | } 56 | 57 | #pragma warning restore 58 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.InterfacesWithDifferentCasing#IApi.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IApi.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIApi 17 | : global::RefitGeneratorTest.IApi 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIApi(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IApi.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.InterfacesWithDifferentCasing#Iapi1.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: Iapi1.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIapi 17 | : global::RefitGeneratorTest.Iapi 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIapi(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.Iapi.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.InterfacesWithDifferentSignature#IApi.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IApi.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIApi 17 | : global::RefitGeneratorTest.IApi 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIApi(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IApi.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.InterfacesWithDifferentSignature#IApi1.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IApi1.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIApi 17 | : global::RefitGeneratorTest.IApi 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIApi(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IApi.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#IGeneratedInterface.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedInterface.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class NestedRefitGeneratorTestIGeneratedInterface 17 | : global::Nested.RefitGeneratorTest.IGeneratedInterface 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public NestedRefitGeneratorTestIGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::Nested.RefitGeneratorTest.IGeneratedInterface.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.NonRefitMethodShouldRaiseDiagnostic.verified.txt: -------------------------------------------------------------------------------- 1 | { 2 | Diagnostics: [ 3 | { 4 | Location: /* 5 | 6 | void NonRefitMethod(); 7 | ^^^^^^^^^^^^^^ 8 | } 9 | */ 10 | : (16,5)-(16,19), 11 | Message: Method IGeneratedClient.NonRefitMethod either has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument, 12 | Severity: Warning, 13 | WarningLevel: 1, 14 | Descriptor: { 15 | Id: RF001, 16 | Title: Refit types must have Refit HTTP method attributes, 17 | MessageFormat: Method {0}.{1} either has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument, 18 | Category: Refit, 19 | DefaultSeverity: Warning, 20 | IsEnabledByDefault: true 21 | } 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.RefitInterfaceDerivedFromBaseTest.verified.txt: -------------------------------------------------------------------------------- 1 | { 2 | Diagnostics: [ 3 | { 4 | Location: /* 5 | { 6 | void NonRefitMethod(); 7 | ^^^^^^^^^^^^^^ 8 | } 9 | */ 10 | : (19,9)-(19,23), 11 | Message: Method IBaseInterface.NonRefitMethod either has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument, 12 | Severity: Warning, 13 | WarningLevel: 1, 14 | Descriptor: { 15 | Id: RF001, 16 | Title: Refit types must have Refit HTTP method attributes, 17 | MessageFormat: Method {0}.{1} either has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument, 18 | Category: Refit, 19 | DefaultSeverity: Warning, 20 | IsEnabledByDefault: true 21 | } 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/InterfaceTests.RefitInterfaceDerivedFromRefitBaseTest#IBaseInterface.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IBaseInterface.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIBaseInterface 17 | : global::RefitGeneratorTest.IBaseInterface 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIBaseInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task GetPosts() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("GetPosts", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IBaseInterface.GetPosts() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("GetPosts", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/MethodTests.MethodsWithGenericConstraints.verified.txt: -------------------------------------------------------------------------------- 1 | { 2 | Diagnostics: [ 3 | { 4 | Location: /* 5 | 6 | void NonRefitMethod() 7 | ^^^^^^^^^^^^^^ 8 | where T1 : class 9 | */ 10 | : (21,5)-(21,19), 11 | Message: Method IGeneratedClient.NonRefitMethod either has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument, 12 | Severity: Warning, 13 | WarningLevel: 1, 14 | Descriptor: { 15 | Id: RF001, 16 | Title: Refit types must have Refit HTTP method attributes, 17 | MessageFormat: Method {0}.{1} either has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument, 18 | Category: Refit, 19 | DefaultSeverity: Warning, 20 | IsEnabledByDefault: true 21 | } 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/ParameterTests.NullableRouteParameter#IGeneratedClient.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedClient.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedClient 17 | : global::RefitGeneratorTest.IGeneratedClient 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(string) }; 32 | 33 | /// 34 | public async global::System.Threading.Tasks.Task Get(string? @user) 35 | { 36 | var ______arguments = new object[] { @user }; 37 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters ); 38 | 39 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 40 | } 41 | 42 | private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(string) }; 43 | 44 | /// 45 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get(string? @user) 46 | { 47 | var ______arguments = new object[] { @user }; 48 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters0 ); 49 | 50 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 51 | } 52 | } 53 | } 54 | } 55 | 56 | #pragma warning restore 57 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/ParameterTests.NullableValueTypeRouteParameter#IGeneratedClient.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedClient.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedClient 17 | : global::RefitGeneratorTest.IGeneratedClient 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(int?) }; 32 | 33 | /// 34 | public async global::System.Threading.Tasks.Task Get(int? @user) 35 | { 36 | var ______arguments = new object[] { @user }; 37 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters ); 38 | 39 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 40 | } 41 | 42 | private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(int?) }; 43 | 44 | /// 45 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get(int? @user) 46 | { 47 | var ______arguments = new object[] { @user }; 48 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters0 ); 49 | 50 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 51 | } 52 | } 53 | } 54 | } 55 | 56 | #pragma warning restore 57 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/ParameterTests.RouteParameter#IGeneratedClient.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedClient.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedClient 17 | : global::RefitGeneratorTest.IGeneratedClient 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(string) }; 32 | 33 | /// 34 | public async global::System.Threading.Tasks.Task Get(string @user) 35 | { 36 | var ______arguments = new object[] { @user }; 37 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters ); 38 | 39 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 40 | } 41 | 42 | private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(string) }; 43 | 44 | /// 45 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get(string @user) 46 | { 47 | var ______arguments = new object[] { @user }; 48 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters0 ); 49 | 50 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 51 | } 52 | } 53 | } 54 | } 55 | 56 | #pragma warning restore 57 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/ParameterTests.ValueTypeRouteParameter#IGeneratedClient.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedClient.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedClient 17 | : global::RefitGeneratorTest.IGeneratedClient 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(int) }; 32 | 33 | /// 34 | public async global::System.Threading.Tasks.Task Get(int @user) 35 | { 36 | var ______arguments = new object[] { @user }; 37 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters ); 38 | 39 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 40 | } 41 | 42 | private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(int) }; 43 | 44 | /// 45 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get(int @user) 46 | { 47 | var ______arguments = new object[] { @user }; 48 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", ______typeParameters0 ); 49 | 50 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 51 | } 52 | } 53 | } 54 | } 55 | 56 | #pragma warning restore 57 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericConstraintReturnTask#IGeneratedClient.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedClient.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedClient 17 | : global::RefitGeneratorTest.IGeneratedClient 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | where T : class, global::System.IDisposable, new() 34 | { 35 | var ______arguments = global::System.Array.Empty(); 36 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty(), new global::System.Type[] { typeof(T) } ); 37 | 38 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 39 | } 40 | 41 | /// 42 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() 43 | where T : class 44 | { 45 | var ______arguments = global::System.Array.Empty(); 46 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty(), new global::System.Type[] { typeof(T) } ); 47 | 48 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 49 | } 50 | } 51 | } 52 | } 53 | 54 | #pragma warning restore 55 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericStructConstraintReturnTask#IGeneratedClient.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedClient.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedClient 17 | : global::RefitGeneratorTest.IGeneratedClient 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | where T : struct 34 | { 35 | var ______arguments = global::System.Array.Empty(); 36 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty(), new global::System.Type[] { typeof(T) } ); 37 | 38 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 39 | } 40 | 41 | /// 42 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() 43 | where T : struct 44 | { 45 | var ______arguments = global::System.Array.Empty(); 46 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty(), new global::System.Type[] { typeof(T) } ); 47 | 48 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 49 | } 50 | } 51 | } 52 | } 53 | 54 | #pragma warning restore 55 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#IGeneratedClient.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedClient.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedClient 17 | : global::RefitGeneratorTest.IGeneratedClient 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericUnmanagedConstraintReturnTask#IGeneratedClient.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedClient.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedClient 17 | : global::RefitGeneratorTest.IGeneratedClient 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | where T : unmanaged 34 | { 35 | var ______arguments = global::System.Array.Empty(); 36 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty(), new global::System.Type[] { typeof(T) } ); 37 | 38 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 39 | } 40 | 41 | /// 42 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() 43 | { 44 | var ______arguments = global::System.Array.Empty(); 45 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty(), new global::System.Type[] { typeof(T) } ); 46 | 47 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 48 | } 49 | } 50 | } 51 | } 52 | 53 | #pragma warning restore 54 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/ReturnTypeTests.ReturnNullableObject#IGeneratedClient.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedClient.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedClient 17 | : global::RefitGeneratorTest.IGeneratedClient 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/ReturnTypeTests.ReturnNullableValueType#IGeneratedClient.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedClient.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedClient 17 | : global::RefitGeneratorTest.IGeneratedClient 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Get() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 36 | 37 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); 45 | 46 | return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/ReturnTypeTests.ReturnUnsupportedType#IGeneratedClient.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedClient.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedClient 17 | : global::RefitGeneratorTest.IGeneratedClient 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(string) }; 32 | 33 | /// 34 | public string GetUser(string @user) 35 | { 36 | var ______arguments = new object[] { @user }; 37 | var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUser", ______typeParameters ); 38 | 39 | return (string)______func(this.Client, ______arguments); 40 | } 41 | 42 | private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(string) }; 43 | 44 | /// 45 | string global::RefitGeneratorTest.IGeneratedClient.GetUser(string @user) 46 | { 47 | var ______arguments = new object[] { @user }; 48 | var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUser", ______typeParameters0 ); 49 | 50 | return (string)______func(this.Client, ______arguments); 51 | } 52 | } 53 | } 54 | } 55 | 56 | #pragma warning restore 57 | -------------------------------------------------------------------------------- /Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#IGeneratedClient.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGeneratedClient.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitGeneratorTestIGeneratedClient 17 | : global::RefitGeneratorTest.IGeneratedClient 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task Post() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Post", global::System.Array.Empty() ); 36 | 37 | await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Post() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("Post", global::System.Array.Empty() ); 45 | 46 | await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | 52 | #pragma warning restore 53 | -------------------------------------------------------------------------------- /Refit.HttpClientFactory/Refit.HttpClientFactory.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Refit HTTP Client Factory Extensions 5 | Refit HTTP Client Factory Extensions 6 | $(RefitTargets) 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Refit.HttpClientFactory/SettingsFor.cs: -------------------------------------------------------------------------------- 1 | namespace Refit 2 | { 3 | /// 4 | /// ISettingsFor 5 | /// 6 | public interface ISettingsFor 7 | { 8 | /// 9 | /// Gets the settings. 10 | /// 11 | /// 12 | /// The settings. 13 | /// 14 | RefitSettings? Settings { get; } 15 | } 16 | 17 | /// 18 | /// SettingsFor. 19 | /// 20 | /// 21 | /// 22 | /// 23 | /// Initializes a new instance of the class. 24 | /// 25 | /// The settings. 26 | public class SettingsFor(RefitSettings? settings) : ISettingsFor 27 | { 28 | /// 29 | /// Gets the settings. 30 | /// 31 | /// 32 | /// The settings. 33 | /// 34 | public RefitSettings? Settings { get; } = settings; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Refit.Newtonsoft.Json/Refit.Newtonsoft.Json.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Refit Serializer for Newtonsoft.Json ($(TargetFramework)) 5 | Refit Serializers for Newtonsoft.Json 6 | $(RefitTargets) 7 | true 8 | Refit 9 | enable 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Refit.Tests/API/ApiApprovalTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | #if !NET48 7 | using System.Diagnostics.CodeAnalysis; 8 | 9 | namespace Refit.Tests.API; 10 | 11 | /// 12 | /// Checks to make sure that the API is consistent with previous releases, and new API changes are highlighted. 13 | /// 14 | [ExcludeFromCodeCoverage] 15 | public class ApiApprovalTests 16 | { 17 | /// 18 | /// Generates public API for the ReactiveUI API. 19 | /// 20 | /// A task to monitor the process. 21 | [Fact] 22 | public Task Refit() => typeof(ApiResponse).Assembly.CheckApproval(["Refit"]); 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /Refit.Tests/API/ApiExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | #if !NET48 7 | using System.Diagnostics.CodeAnalysis; 8 | using System.Reflection; 9 | using System.Runtime.CompilerServices; 10 | 11 | using PublicApiGenerator; 12 | 13 | using VerifyXunit; 14 | 15 | namespace Refit.Tests; 16 | 17 | /// 18 | /// A helper for doing API approvals. 19 | /// 20 | [ExcludeFromCodeCoverage] 21 | public static class ApiExtensions 22 | { 23 | /// 24 | /// Checks to make sure the API is approved. 25 | /// 26 | /// The assembly that is being checked. 27 | /// The namespaces. 28 | /// The caller file path. 29 | /// 30 | /// A Task. 31 | /// 32 | public static async Task CheckApproval(this Assembly assembly, string[] namespaces, [CallerFilePath] string filePath = "") 33 | { 34 | var generatorOptions = new ApiGeneratorOptions { AllowNamespacePrefixes = namespaces }; 35 | var apiText = assembly.GeneratePublicApi(generatorOptions); 36 | var result = await Verifier.Verify(apiText, null, filePath) 37 | .UniqueForRuntimeAndVersion() 38 | .ScrubEmptyLines() 39 | .ScrubLines(l => 40 | l.StartsWith("[assembly: AssemblyVersion(", StringComparison.InvariantCulture) || 41 | l.StartsWith("[assembly: AssemblyFileVersion(", StringComparison.InvariantCulture) || 42 | l.StartsWith("[assembly: AssemblyInformationalVersion(", StringComparison.InvariantCulture) || 43 | l.StartsWith("[assembly: System.Reflection.AssemblyMetadata(", StringComparison.InvariantCulture)); 44 | } 45 | } 46 | #endif 47 | -------------------------------------------------------------------------------- /Refit.Tests/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Refit.Tests/CamelCaseUrlParameterKeyFormatter.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | 3 | namespace Refit.Tests; 4 | 5 | public class CamelCaselTestsRequest 6 | { 7 | public string alreadyCamelCased { get; set; } 8 | public string NOTCAMELCased { get; set; } 9 | } 10 | 11 | public class CamelCaseUrlParameterKeyFormatterTests 12 | { 13 | [Fact] 14 | public void Format_EmptyKey_ReturnsEmptyKey() 15 | { 16 | var urlParameterKeyFormatter = new CamelCaseUrlParameterKeyFormatter(); 17 | 18 | var output = urlParameterKeyFormatter.Format(string.Empty); 19 | Assert.Equal(string.Empty, output); 20 | } 21 | 22 | [Fact] 23 | public void FormatKey_Returns_ExpectedValue() 24 | { 25 | var urlParameterKeyFormatter = new CamelCaseUrlParameterKeyFormatter(); 26 | 27 | var refitSettings = new RefitSettings 28 | { 29 | UrlParameterKeyFormatter = urlParameterKeyFormatter 30 | }; 31 | var fixture = new RequestBuilderImplementation(refitSettings); 32 | var factory = fixture.BuildRequestFactoryForMethod( 33 | nameof(IDummyHttpApi.ComplexQueryObjectWithDictionary) 34 | ); 35 | 36 | var complexQuery = new CamelCaselTestsRequest 37 | { 38 | alreadyCamelCased = "value1", 39 | NOTCAMELCased = "value2" 40 | }; 41 | 42 | var output = factory([complexQuery]); 43 | var uri = new Uri(new Uri("http://api"), output.RequestUri); 44 | 45 | Assert.Equal("/foo?alreadyCamelCased=value1¬camelCased=value2", uri.PathAndQuery); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Refit.Tests/DeliminatorSeparatedPropertyNamesContractResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Text; 5 | using Newtonsoft.Json.Serialization; 6 | 7 | namespace Refit.Tests; 8 | 9 | public class DeliminatorSeparatedPropertyNamesContractResolver : DefaultContractResolver 10 | { 11 | readonly string separator; 12 | 13 | protected DeliminatorSeparatedPropertyNamesContractResolver(char separator) 14 | { 15 | this.separator = separator.ToString(CultureInfo.InvariantCulture); 16 | } 17 | 18 | protected override string ResolvePropertyName(string propertyName) 19 | { 20 | var parts = new List(); 21 | var currentWord = new StringBuilder(); 22 | 23 | foreach (var c in propertyName.ToCharArray()) 24 | { 25 | if (Char.IsUpper(c) && currentWord.Length > 0) 26 | { 27 | parts.Add(currentWord.ToString()); 28 | currentWord.Clear(); 29 | } 30 | 31 | currentWord.Append(char.ToLower(c)); 32 | } 33 | 34 | if (currentWord.Length > 0) 35 | { 36 | parts.Add(currentWord.ToString()); 37 | } 38 | 39 | return String.Join(separator, parts.ToArray()); 40 | } 41 | } 42 | 43 | public class SnakeCasePropertyNamesContractResolver 44 | : DeliminatorSeparatedPropertyNamesContractResolver 45 | { 46 | public SnakeCasePropertyNamesContractResolver() 47 | : base('_') { } 48 | } 49 | -------------------------------------------------------------------------------- /Refit.Tests/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | using System.Diagnostics.CodeAnalysis; 7 | 8 | [assembly: SuppressMessage( 9 | "CodeQuality", 10 | "IDE0079:Remove unnecessary suppression", 11 | Justification = "", 12 | Scope = "member", 13 | Target = "~T:Refit.Tests.RequestBuilderTests" 14 | )] 15 | [assembly: SuppressMessage( 16 | "CodeQuality", 17 | "IDE0079:Remove unnecessary suppression", 18 | Justification = "", 19 | Scope = "member", 20 | Target = "~T:Refit.Tests.MultipartTests" 21 | )] 22 | -------------------------------------------------------------------------------- /Refit.Tests/IFooWithOtherAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Threading.Tasks; 3 | using Refit; 4 | 5 | interface IFooWithOtherAttribute 6 | { 7 | [Get("/")] 8 | Task GetRoot(); 9 | 10 | [DisplayName("/")] 11 | Task PostRoot(); 12 | } 13 | -------------------------------------------------------------------------------- /Refit.Tests/IInterfaceWithoutRefit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Refit.Tests; 8 | 9 | public interface IInterfaceWithoutRefit 10 | { 11 | Task DoSomething(); 12 | } 13 | -------------------------------------------------------------------------------- /Refit.Tests/IServiceWithoutNamespace.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using Refit; 6 | 7 | interface IServiceWithoutNamespace 8 | { 9 | [Get("/")] 10 | Task GetRoot(); 11 | 12 | [Post("/")] 13 | Task PostRoot(); 14 | } 15 | -------------------------------------------------------------------------------- /Refit.Tests/InheritedGenericInterfacesApi.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using Newtonsoft.Json; 4 | using Refit; // InterfaceStubGenerator looks for this 5 | using static System.Math; // This is here to verify https://github.com/reactiveui/refit/issues/283 6 | 7 | namespace Refit.Tests; 8 | 9 | public class DataEntity { } 10 | 11 | public interface IDataApiA : IDataCrudApi 12 | { 13 | [Get("")] 14 | Task PingA(); 15 | } 16 | 17 | public interface IDataApiB : IDataCrudApi 18 | { 19 | [Get("")] 20 | Task PingB(); 21 | } 22 | 23 | public interface IDataCrudApi : IDataCrudApi 24 | where T : class 25 | { 26 | [Post("")] 27 | Task Copy([Body] T payload); 28 | } 29 | 30 | public interface IDataCrudApi 31 | where T : class 32 | { 33 | [Post("")] 34 | Task Create([Body] T payload); 35 | 36 | [Get("")] 37 | Task> ReadAll() 38 | where TFoo : new(); 39 | 40 | [Get("")] 41 | Task> ReadAll() 42 | where TFoo : new() 43 | where TBar : struct; 44 | 45 | [Get("/{key}")] 46 | Task ReadOne(TKey key); 47 | 48 | [Put("/{key}")] 49 | Task Update(TKey key, [Body] T payload); 50 | 51 | [Delete("/{key}")] 52 | Task Delete(TKey key); 53 | 54 | [Get("")] 55 | Task ReadAllClasses() 56 | where TFoo : class, new(); 57 | } 58 | 59 | public class DatasetQueryItem 60 | where TResultRow : class, new() 61 | { 62 | [JsonProperty("global_id")] 63 | public long GlobalId { get; set; } 64 | 65 | public long Number { get; set; } 66 | 67 | [JsonProperty("Cells")] 68 | public TResultRow Value { get; set; } 69 | } 70 | 71 | public interface IDataMosApi 72 | { 73 | [Get("/datasets/{dataSet}/rows")] 74 | Task[]> GetDataSetItems() 75 | where TResulRow : class, new(); 76 | } 77 | -------------------------------------------------------------------------------- /Refit.Tests/InheritedInterfacesInSeparateFileApi.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Refit; // InterfaceStubGenerator looks for this 3 | 4 | namespace Refit.Tests.SeparateNamespace; 5 | 6 | public interface InheritedInterfacesInSeparateFileApi : IAmInterfaceF_RequireUsing 7 | { 8 | [Get("/get")] 9 | Task Get(int i); 10 | } 11 | -------------------------------------------------------------------------------- /Refit.Tests/IntegrationTestHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Net; 7 | using System.Net.Http; 8 | using System.Runtime.CompilerServices; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | 12 | namespace Refit.Tests; 13 | 14 | public static class IntegrationTestHelper 15 | { 16 | public static string GetPath(params string[] paths) 17 | { 18 | var ret = GetIntegrationTestRootDirectory(); 19 | return (new FileInfo(paths.Aggregate(ret, Path.Combine))).FullName; 20 | } 21 | 22 | public static string GetIntegrationTestRootDirectory([CallerFilePath] string filePath = default) 23 | { 24 | // XXX: This is an evil hack, but it's okay for a unit test 25 | // We can't use Assembly.Location because unit test runners love 26 | // to move stuff to temp directories 27 | var di = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(filePath))); 28 | 29 | return di.FullName; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Refit.Tests/ModuleInitializer.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | using VerifyTests.DiffPlex; 3 | 4 | namespace Refit.Tests; 5 | 6 | static class ModuleInitializer 7 | { 8 | // ModuleInitializer should only be used in apps 9 | #pragma warning disable CA2255 10 | [ModuleInitializer] 11 | #pragma warning restore CA2255 12 | public static void Init() 13 | { 14 | DerivePathInfo((file, _, type, method) => new(Path.Combine(Path.GetDirectoryName(file), "_snapshots"), type.Name, method.Name)); 15 | 16 | VerifySourceGenerators.Initialize(); 17 | VerifyDiffPlex.Initialize(OutputType.Compact); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Refit.Tests/ModuleInitializerAttribute.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | namespace System.Runtime.CompilerServices; 3 | 4 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 5 | sealed class ModuleInitializerAttribute : Attribute; 6 | -------------------------------------------------------------------------------- /Refit.Tests/MyQueryParams.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Refit.Tests; 6 | 7 | public record MySimpleQueryParams 8 | { 9 | public string FirstName { get; set; } 10 | 11 | [AliasAs("lName")] 12 | public string LastName { get; set; } 13 | } 14 | 15 | public class MyComplexQueryParams 16 | { 17 | public string FirstName { get; set; } 18 | 19 | public string LastName { get; set; } 20 | 21 | [AliasAs("Addr")] 22 | public Address Address { get; set; } = new Address(); 23 | 24 | public Dictionary MetaData { get; set; } = new Dictionary(); 25 | 26 | public List Other { get; set; } = new List(); 27 | } 28 | 29 | public record Address 30 | { 31 | [AliasAs("Zip")] 32 | public int Postcode { get; set; } 33 | public string Street { get; set; } 34 | } 35 | -------------------------------------------------------------------------------- /Refit.Tests/NamespaceCollisionApi.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CollisionB; 3 | using Refit; // InterfaceStubGenerator looks for this 4 | using SomeType = CollisionA.SomeType; 5 | 6 | namespace Refit.Tests 7 | { 8 | public interface INamespaceCollisionApi 9 | { 10 | [Get("/")] 11 | Task SomeRequest(); 12 | } 13 | 14 | public static class NamespaceCollisionApi 15 | { 16 | public static INamespaceCollisionApi Create() 17 | { 18 | return RestService.For("http://somewhere.com"); 19 | } 20 | } 21 | } 22 | 23 | namespace CollisionA 24 | { 25 | public class SomeType { } 26 | 27 | public interface INamespaceCollisionApi 28 | { 29 | [Get("/")] 30 | Task SomeRequest(); 31 | } 32 | } 33 | 34 | namespace CollisionB 35 | { 36 | public class SomeType { } 37 | 38 | public interface INamespaceCollisionApi 39 | { 40 | [Get("/")] 41 | Task SomeRequest(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Refit.Tests/NamespaceOverlapApi.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Common.Helper; 4 | // InterfaceStubGenerator looks for this 5 | using Refit; 6 | using Refit.Tests.Common; 7 | 8 | namespace Refit.Tests 9 | { 10 | [SomeHelper] 11 | public interface INamespaceOverlapApi 12 | { 13 | [Get("/")] 14 | Task SomeRequest(); 15 | } 16 | 17 | public static class NamespaceOverlapApi 18 | { 19 | public static INamespaceOverlapApi Create() 20 | { 21 | return RestService.For("http://somewhere.com"); 22 | } 23 | } 24 | } 25 | 26 | namespace Common.Helper 27 | { 28 | public class SomeHelperAttribute : Attribute { } 29 | } 30 | 31 | namespace Refit.Tests.Common 32 | { 33 | public class SomeOtherType { } 34 | } 35 | -------------------------------------------------------------------------------- /Refit.Tests/NamespaceWithGlobalAliasApi.cs: -------------------------------------------------------------------------------- 1 | using global::System.Threading.Tasks; 2 | using Refit; // InterfaceStubGenerator looks for this 3 | 4 | namespace Refit.Tests 5 | { 6 | using global::Refit.Tests.SomeNamespace; 7 | 8 | public interface NamespaceWithGlobalAliasApi 9 | { 10 | [Get("/")] 11 | Task SomeRequest(); 12 | } 13 | } 14 | 15 | namespace Refit.Tests.SomeNamespace 16 | { 17 | public class SomeType { } 18 | } 19 | -------------------------------------------------------------------------------- /Refit.Tests/NullableReferenceTypes.cs: -------------------------------------------------------------------------------- 1 | #nullable enable 2 | 3 | using System.Threading.Tasks; 4 | using Refit; // InterfaceStubGenerator looks for this 5 | 6 | namespace Refit.Tests; 7 | 8 | interface IGenericWithResultService 9 | { 10 | [Get("/")] 11 | Task Get(); 12 | } 13 | 14 | interface IGenericWithNullableValueService 15 | { 16 | [Get("/")] 17 | Task Get(); 18 | } 19 | 20 | interface IGenericNullableReferenceService 21 | { 22 | [Get("/")] 23 | Task? Get(); 24 | } 25 | 26 | interface IGenericNullableValueService 27 | { 28 | [Get("/")] 29 | ValueTask? Get(); 30 | } 31 | 32 | interface IGenericNullableWithNullableReferenceService 33 | { 34 | [Get("/")] 35 | Task? Get(); 36 | } 37 | 38 | interface IGenericNullableWithNullableValueService 39 | { 40 | [Get("/")] 41 | ValueTask? Get(); 42 | } 43 | 44 | interface INullableReferenceService 45 | { 46 | [Get("/")] 47 | string? Get(); 48 | } 49 | 50 | interface INullableValueService 51 | { 52 | [Get("/")] 53 | int? Get(); 54 | } 55 | 56 | interface IReferenceAndValueParametersService 57 | { 58 | [Get("/")] 59 | Task Get(string? reference, int? value); 60 | } 61 | 62 | interface IGenericNullableReferenceParameterService 63 | { 64 | [Get("/")] 65 | Task Get(System.Collections.Generic.List? reference); 66 | } 67 | 68 | interface IGenericWithNullableReferenceParameterService 69 | { 70 | [Get("/")] 71 | Task Get(System.Collections.Generic.List reference); 72 | } 73 | 74 | interface IGenericNullableWithNullableReferenceParameterService 75 | { 76 | [Get("/")] 77 | Task Get(System.Collections.Generic.List? reference); 78 | } 79 | 80 | interface ICustomNullableReferenceService 81 | { 82 | [Get("/")] 83 | CustomReferenceType? Get(); 84 | } 85 | 86 | interface ICustomNullableValueService 87 | { 88 | [Get("/")] 89 | CustomValueType? Get(); 90 | } 91 | 92 | interface ICustomReferenceAndValueParametersService 93 | { 94 | [Get("/")] 95 | Task Get(CustomReferenceType? reference, CustomValueType? value); 96 | } 97 | 98 | class CustomReferenceType { } 99 | 100 | class CustomValueType { } 101 | -------------------------------------------------------------------------------- /Refit.Tests/PartialInterfacesApi.First.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Refit; // InterfaceStubGenerator looks for this 3 | 4 | namespace Refit.Tests; 5 | 6 | public partial interface PartialInterfacesApi 7 | { 8 | [Get("/get?result=First")] 9 | Task First(); 10 | } 11 | -------------------------------------------------------------------------------- /Refit.Tests/PartialInterfacesApi.Second.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Refit; // InterfaceStubGenerator looks for this 3 | 4 | namespace Refit.Tests; 5 | 6 | public partial interface PartialInterfacesApi 7 | { 8 | [Get("/get?result=Second")] 9 | Task Second(); 10 | } 11 | -------------------------------------------------------------------------------- /Refit.Tests/ReducedUsingInsideNamespaceApi.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Refit; // InterfaceStubGenerator looks for this 3 | 4 | namespace Refit.Tests 5 | { 6 | using ModelNamespace; 7 | 8 | public interface IReducedUsingInsideNamespaceApi 9 | { 10 | [Get("/")] 11 | Task SomeRequest(); 12 | } 13 | } 14 | 15 | namespace Refit.Tests.ModelNamespace 16 | { 17 | public class SomeType { } 18 | } 19 | -------------------------------------------------------------------------------- /Refit.Tests/RefitSettings.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | 3 | namespace Refit.Tests; 4 | 5 | public class RefitSettingsTests 6 | { 7 | [Fact] 8 | public void Can_CreateRefitSettings_WithoutException() 9 | { 10 | var contentSerializer = new NewtonsoftJsonContentSerializer(); 11 | var urlParameterFormatter = new DefaultUrlParameterFormatter(); 12 | var urlParameterKeyFormatter = new CamelCaseUrlParameterKeyFormatter(); 13 | var formUrlEncodedParameterFormatter = new DefaultFormUrlEncodedParameterFormatter(); 14 | 15 | var exception = Record.Exception(() => new RefitSettings()); 16 | Assert.Null(exception); 17 | 18 | exception = Record.Exception(() => new RefitSettings(contentSerializer)); 19 | Assert.Null(exception); 20 | 21 | exception = Record.Exception( 22 | () => new RefitSettings(contentSerializer, urlParameterFormatter) 23 | ); 24 | Assert.Null(exception); 25 | 26 | exception = Record.Exception( 27 | () => 28 | new RefitSettings( 29 | contentSerializer, 30 | urlParameterFormatter, 31 | formUrlEncodedParameterFormatter 32 | ) 33 | ); 34 | Assert.Null(exception); 35 | 36 | exception = Record.Exception( 37 | () => 38 | new RefitSettings( 39 | contentSerializer, 40 | urlParameterFormatter, 41 | formUrlEncodedParameterFormatter, 42 | urlParameterKeyFormatter 43 | ) 44 | ); 45 | Assert.Null(exception); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Refit.Tests/Test Files/Test.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reactiveui/refit/8a48c63a071bebd82758440352db5b58551bc94f/Refit.Tests/Test Files/Test.pdf -------------------------------------------------------------------------------- /Refit.Tests/TypeCollisionApiA.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CollisionA; 3 | using Refit; // InterfaceStubGenerator looks for this 4 | 5 | namespace Refit.Tests; 6 | 7 | public interface ITypeCollisionApiA 8 | { 9 | [Get("")] 10 | Task SomeARequest(); 11 | } 12 | 13 | public static class TypeCollisionApiA 14 | { 15 | public static ITypeCollisionApiA Create() 16 | { 17 | return RestService.For("http://somewhere.com"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Refit.Tests/TypeCollisionApiB.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using CollisionB; 3 | using Refit; // InterfaceStubGenerator looks for this 4 | 5 | namespace Refit.Tests; 6 | 7 | public interface ITypeCollisionApiB 8 | { 9 | [Get("")] 10 | Task SomeBRequest(); 11 | } 12 | 13 | public static class TypeCollisionApiB 14 | { 15 | public static ITypeCollisionApiB Create() 16 | { 17 | return RestService.For("http://somewhere.com"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Refit.Tests/UniqueNameTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Xunit; 3 | 4 | namespace Refit.Tests 5 | { 6 | namespace Http 7 | { 8 | class Client 9 | { 10 | public class Request { } 11 | 12 | public class Response { } 13 | } 14 | } 15 | 16 | namespace Tcp 17 | { 18 | class Client { } 19 | } 20 | 21 | public class UniqueNameTests 22 | { 23 | [Fact] 24 | public void SystemTypeAndLanguageTypeHaveSameNames() 25 | { 26 | var name1 = UniqueName.ForType(); 27 | var name2 = UniqueName.ForType(); 28 | 29 | Assert.Equal(name1, name2); 30 | } 31 | 32 | [Fact] 33 | public void GenericClassWithDifferentTypesHaveUniqueNames() 34 | { 35 | var name1 = UniqueName.ForType>(); 36 | var name2 = UniqueName.ForType>(); 37 | 38 | Assert.NotEqual(name1, name2); 39 | } 40 | 41 | [Fact] 42 | public void SameClassNameInDifferentNamespacesHaveUniqueNames() 43 | { 44 | var name1 = UniqueName.ForType(); 45 | var name2 = UniqueName.ForType(); 46 | 47 | Assert.NotEqual(name1, name2); 48 | } 49 | 50 | [Fact] 51 | public void ClassesWithNestedClassesHaveUniqueNames() 52 | { 53 | var name1 = UniqueName.ForType(); 54 | var name2 = UniqueName.ForType(); 55 | 56 | Assert.NotEqual(name1, name2); 57 | } 58 | 59 | [Fact] 60 | public void NestedClassesHaveUniqueNames() 61 | { 62 | var name1 = UniqueName.ForType(); 63 | var name2 = UniqueName.ForType(); 64 | 65 | Assert.NotEqual(name1, name2); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Refit.Tests/Verifiers/CSharpIncrementalSourceGeneratorVerifier`1+Test.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.CodeAnalysis; 3 | using Microsoft.CodeAnalysis.CSharp; 4 | using Microsoft.CodeAnalysis.CSharp.Testing; 5 | using Microsoft.CodeAnalysis.Testing; 6 | 7 | namespace Refit.Tests; 8 | 9 | public static partial class CSharpIncrementalSourceGeneratorVerifier 10 | where TIncrementalGenerator : IIncrementalGenerator, new() 11 | { 12 | public class Test : CSharpSourceGeneratorTest 13 | { 14 | public Test() 15 | { 16 | SolutionTransforms.Add( 17 | (solution, projectId) => 18 | { 19 | var compilationOptions = solution.GetProject(projectId).CompilationOptions; 20 | compilationOptions = compilationOptions.WithSpecificDiagnosticOptions( 21 | compilationOptions.SpecificDiagnosticOptions.SetItems( 22 | CSharpVerifierHelper.NullableWarnings 23 | ) 24 | ); 25 | solution = solution.WithProjectCompilationOptions( 26 | projectId, 27 | compilationOptions 28 | ); 29 | 30 | return solution; 31 | } 32 | ); 33 | } 34 | 35 | /// 36 | /// Gets the source generators. 37 | /// 38 | /// 39 | protected override IEnumerable GetSourceGenerators() 40 | { 41 | yield return new TIncrementalGenerator().AsSourceGenerator().GetGeneratorType(); 42 | } 43 | 44 | /// 45 | /// Creates the parse options. 46 | /// 47 | /// 48 | protected override ParseOptions CreateParseOptions() 49 | { 50 | var parseOptions = (CSharpParseOptions)base.CreateParseOptions(); 51 | return parseOptions.WithLanguageVersion(LanguageVersion.Preview); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Refit.Tests/Verifiers/CSharpIncrementalSourceGeneratorVerifier`1.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | 3 | namespace Refit.Tests; 4 | 5 | public static partial class CSharpIncrementalSourceGeneratorVerifier 6 | where TIncrementalGenerator : IIncrementalGenerator, new(); 7 | -------------------------------------------------------------------------------- /Refit.Tests/Verifiers/CSharpSourceGeneratorVerifier`1+Test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.CodeAnalysis; 3 | using Microsoft.CodeAnalysis.CSharp.Testing; 4 | using Microsoft.CodeAnalysis.Testing; 5 | 6 | namespace Refit.Tests; 7 | 8 | public static partial class CSharpSourceGeneratorVerifier 9 | where TSourceGenerator : ISourceGenerator, new() 10 | { 11 | public class Test : CSharpSourceGeneratorTest 12 | { 13 | public Test() 14 | { 15 | SolutionTransforms.Add( 16 | (solution, projectId) => 17 | { 18 | var compilationOptions = solution.GetProject(projectId).CompilationOptions; 19 | compilationOptions = compilationOptions.WithSpecificDiagnosticOptions( 20 | compilationOptions.SpecificDiagnosticOptions.SetItems( 21 | CSharpVerifierHelper.NullableWarnings 22 | ) 23 | ); 24 | solution = solution.WithProjectCompilationOptions( 25 | projectId, 26 | compilationOptions 27 | ); 28 | 29 | return solution; 30 | } 31 | ); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Refit.Tests/Verifiers/CSharpSourceGeneratorVerifier`1.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | 3 | namespace Refit.Tests; 4 | 5 | public static partial class CSharpSourceGeneratorVerifier 6 | where TSourceGenerator : ISourceGenerator, new(); 7 | -------------------------------------------------------------------------------- /Refit.Tests/Verifiers/CSharpVerifierHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Immutable; 3 | using Microsoft.CodeAnalysis; 4 | using Microsoft.CodeAnalysis.CSharp; 5 | 6 | namespace Refit.Tests; 7 | 8 | static class CSharpVerifierHelper 9 | { 10 | /// 11 | /// By default, the compiler reports diagnostics for nullable reference types at 12 | /// , and the analyzer test framework defaults to only validating 13 | /// diagnostics at . This map contains all compiler diagnostic IDs 14 | /// related to nullability mapped to , which is then used to enable all 15 | /// of these warnings for default validation during analyzer and code fix tests. 16 | /// 17 | internal static ImmutableDictionary NullableWarnings { get; } = 18 | GetNullableWarningsFromCompiler(); 19 | 20 | static ImmutableDictionary GetNullableWarningsFromCompiler() 21 | { 22 | string[] args = { "/warnaserror:nullable" }; 23 | var commandLineArguments = CSharpCommandLineParser.Default.Parse( 24 | args, 25 | baseDirectory: Environment.CurrentDirectory, 26 | sdkDirectory: Environment.CurrentDirectory 27 | ); 28 | return commandLineArguments.CompilationOptions.SpecificDiagnosticOptions; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Refit.Tests/_snapshots/InterfaceStubGeneratorTests.FindInterfacesSmokeTest#Generated.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: Generated.g.cs 2 | 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | /// 8 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 9 | [global::System.Diagnostics.DebuggerNonUserCode] 10 | [global::RefitInternalGenerated.PreserveAttribute] 11 | [global::System.Reflection.Obfuscation(Exclude=true)] 12 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 13 | internal static partial class Generated 14 | { 15 | #if NET5_0_OR_GREATER 16 | [System.Runtime.CompilerServices.ModuleInitializer] 17 | [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] 18 | public static void Initialize() 19 | { 20 | } 21 | #endif 22 | } 23 | } 24 | #pragma warning restore 25 | -------------------------------------------------------------------------------- /Refit.Tests/_snapshots/InterfaceStubGeneratorTests.FindInterfacesSmokeTest#IGitHubApiDisposable.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: IGitHubApiDisposable.g.cs 2 | #nullable disable 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | partial class Generated 8 | { 9 | 10 | /// 11 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 12 | [global::System.Diagnostics.DebuggerNonUserCode] 13 | [global::RefitInternalGenerated.PreserveAttribute] 14 | [global::System.Reflection.Obfuscation(Exclude=true)] 15 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 16 | partial class RefitTestsIGitHubApiDisposable 17 | : global::Refit.Tests.IGitHubApiDisposable 18 | { 19 | /// 20 | public global::System.Net.Http.HttpClient Client { get; } 21 | readonly global::Refit.IRequestBuilder requestBuilder; 22 | 23 | /// 24 | public RefitTestsIGitHubApiDisposable(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) 25 | { 26 | Client = client; 27 | this.requestBuilder = requestBuilder; 28 | } 29 | 30 | 31 | /// 32 | public async global::System.Threading.Tasks.Task RefitMethod() 33 | { 34 | var ______arguments = global::System.Array.Empty(); 35 | var ______func = requestBuilder.BuildRestResultFuncForMethod("RefitMethod", global::System.Array.Empty() ); 36 | 37 | await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 38 | } 39 | 40 | /// 41 | async global::System.Threading.Tasks.Task global::Refit.Tests.IGitHubApiDisposable.RefitMethod() 42 | { 43 | var ______arguments = global::System.Array.Empty(); 44 | var ______func = requestBuilder.BuildRestResultFuncForMethod("RefitMethod", global::System.Array.Empty() ); 45 | 46 | await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); 47 | } 48 | 49 | /// 50 | void global::System.IDisposable.Dispose() 51 | { 52 | Client?.Dispose(); 53 | } 54 | } 55 | } 56 | } 57 | 58 | #pragma warning restore 59 | -------------------------------------------------------------------------------- /Refit.Tests/_snapshots/InterfaceStubGeneratorTests.FindInterfacesSmokeTest#PreserveAttribute.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: PreserveAttribute.g.cs 2 | 3 | #pragma warning disable 4 | namespace RefitInternalGenerated 5 | { 6 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 7 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 8 | [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)] 9 | sealed class PreserveAttribute : global::System.Attribute 10 | { 11 | // 12 | // Fields 13 | // 14 | public bool AllMembers; 15 | 16 | public bool Conditional; 17 | } 18 | } 19 | #pragma warning restore 20 | -------------------------------------------------------------------------------- /Refit.Tests/_snapshots/InterfaceStubGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#Generated.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: Generated.g.cs 2 | 3 | #pragma warning disable 4 | namespace Refit.Implementation 5 | { 6 | 7 | /// 8 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 9 | [global::System.Diagnostics.DebuggerNonUserCode] 10 | [global::RefitInternalGenerated.PreserveAttribute] 11 | [global::System.Reflection.Obfuscation(Exclude=true)] 12 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 13 | internal static partial class Generated 14 | { 15 | #if NET5_0_OR_GREATER 16 | [System.Runtime.CompilerServices.ModuleInitializer] 17 | [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] 18 | public static void Initialize() 19 | { 20 | } 21 | #endif 22 | } 23 | } 24 | #pragma warning restore 25 | -------------------------------------------------------------------------------- /Refit.Tests/_snapshots/InterfaceStubGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#PreserveAttribute.g.verified.cs: -------------------------------------------------------------------------------- 1 | //HintName: PreserveAttribute.g.cs 2 | 3 | #pragma warning disable 4 | namespace RefitInternalGenerated 5 | { 6 | [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] 7 | [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] 8 | [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)] 9 | sealed class PreserveAttribute : global::System.Attribute 10 | { 11 | // 12 | // Fields 13 | // 14 | public bool AllMembers; 15 | 16 | public bool Conditional; 17 | } 18 | } 19 | #pragma warning restore 20 | -------------------------------------------------------------------------------- /Refit.Xml/Refit.Xml.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Refit Xml Serializer ($(TargetFramework)) 5 | Refit Serializers for Xml 6 | $(RefitTargets) 7 | true 8 | Refit 9 | enable 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Refit/AnonymousDisposable.cs: -------------------------------------------------------------------------------- 1 | namespace Refit 2 | { 3 | sealed class AnonymousDisposable : IDisposable 4 | { 5 | readonly Action block; 6 | 7 | public AnonymousDisposable(Action block) 8 | { 9 | this.block = block; 10 | } 11 | 12 | public void Dispose() 13 | { 14 | block(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Refit/CamelCaseUrlParameterKeyFormatter.cs: -------------------------------------------------------------------------------- 1 | namespace Refit 2 | { 3 | /// 4 | /// Provides an implementation of that formats URL parameter keys in camelCase. 5 | /// 6 | public class CamelCaseUrlParameterKeyFormatter : IUrlParameterKeyFormatter 7 | { 8 | /// 9 | /// Formats the specified key. 10 | /// 11 | /// The key. 12 | /// 13 | public string Format(string key) 14 | { 15 | if (string.IsNullOrEmpty(key) || !char.IsUpper(key[0])) 16 | { 17 | return key; 18 | } 19 | 20 | #if NETCOREAPP 21 | return string.Create( 22 | key.Length, 23 | key, 24 | (chars, name) => 25 | { 26 | name.CopyTo(chars); 27 | FixCasing(chars); 28 | } 29 | ); 30 | #else 31 | char[] chars = key.ToCharArray(); 32 | FixCasing(chars); 33 | return new string(chars); 34 | #endif 35 | } 36 | 37 | private static void FixCasing(Span chars) 38 | { 39 | for (var i = 0; i < chars.Length; i++) 40 | { 41 | if (i == 1 && !char.IsUpper(chars[i])) 42 | { 43 | break; 44 | } 45 | 46 | var hasNext = (i + 1 < chars.Length); 47 | 48 | // Stop when next char is already lowercase. 49 | if (i > 0 && hasNext && !char.IsUpper(chars[i + 1])) 50 | { 51 | break; 52 | } 53 | 54 | chars[i] = char.ToLowerInvariant(chars[i]); 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Refit/CloseGenericMethodKey.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace Refit 4 | { 5 | struct CloseGenericMethodKey : IEquatable 6 | { 7 | internal CloseGenericMethodKey(MethodInfo openMethodInfo, Type[] types) 8 | { 9 | OpenMethodInfo = openMethodInfo; 10 | Types = types; 11 | } 12 | 13 | public MethodInfo OpenMethodInfo { get; } 14 | public Type[] Types { get; } 15 | 16 | public bool Equals(CloseGenericMethodKey other) => 17 | OpenMethodInfo == other.OpenMethodInfo && Types.SequenceEqual(other.Types); 18 | 19 | public override bool Equals(object? obj) 20 | { 21 | if (obj is CloseGenericMethodKey closeGenericMethodKey) 22 | { 23 | return Equals(closeGenericMethodKey); 24 | } 25 | return false; 26 | } 27 | 28 | public override int GetHashCode() 29 | { 30 | unchecked 31 | { 32 | var hash = 17; 33 | hash = hash * 23 + OpenMethodInfo.GetHashCode(); 34 | foreach (var type in Types) 35 | { 36 | hash = hash * 23 + type.GetHashCode(); 37 | } 38 | return hash; 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Refit/CollectionFormat.cs: -------------------------------------------------------------------------------- 1 | namespace Refit 2 | { 3 | /// 4 | /// Collection format defined in https://swagger.io/docs/specification/2-0/describing-parameters/ 5 | /// 6 | public enum CollectionFormat 7 | { 8 | /// 9 | /// Values formatted with or 10 | /// . 11 | /// 12 | RefitParameterFormatter, 13 | 14 | /// 15 | /// Comma-separated values 16 | /// 17 | Csv, 18 | 19 | /// 20 | /// Space-separated values 21 | /// 22 | Ssv, 23 | 24 | /// 25 | /// Tab-separated values 26 | /// 27 | Tsv, 28 | 29 | /// 30 | /// Pipe-separated values 31 | /// 32 | Pipes, 33 | 34 | /// 35 | /// Multiple parameter instances 36 | /// 37 | Multi 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Refit/EnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Refit; 2 | 3 | internal static class EnumerableExtensions 4 | { 5 | internal static EnumerablePeek TryGetSingle(this IEnumerable enumerable, out T? value) 6 | { 7 | value = default; 8 | using var enumerator = enumerable.GetEnumerator(); 9 | var hasFirst = enumerator.MoveNext(); 10 | if (!hasFirst) 11 | return EnumerablePeek.Empty; 12 | 13 | value = enumerator.Current; 14 | if (!enumerator.MoveNext()) 15 | return EnumerablePeek.Single; 16 | 17 | value = default; 18 | return EnumerablePeek.Many; 19 | } 20 | } 21 | 22 | internal static class EmptyDictionary where TKey : notnull 23 | { 24 | private static readonly Dictionary Value = []; 25 | 26 | internal static Dictionary Get() => Value; 27 | } 28 | 29 | internal enum EnumerablePeek 30 | { 31 | Empty, 32 | Single, 33 | Many 34 | } 35 | -------------------------------------------------------------------------------- /Refit/HttpContentExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http; 2 | 3 | namespace Refit 4 | { 5 | #if !NET6_0_OR_GREATER 6 | static class HttpContentExtensions 7 | { 8 | #pragma warning disable IDE0079 // Remove unnecessary suppression 9 | #pragma warning disable IDE0060 // Remove unused parameter 10 | public static Task ReadAsStreamAsync( 11 | this HttpContent httpContent, 12 | CancellationToken cancellationToken 13 | ) 14 | { 15 | return httpContent.ReadAsStreamAsync(); 16 | } 17 | 18 | public static Task ReadAsStringAsync( 19 | this HttpContent httpContent, 20 | CancellationToken cancellationToken 21 | ) 22 | { 23 | return httpContent.ReadAsStringAsync(); 24 | } 25 | #pragma warning restore IDE0060 // Remove unused parameter 26 | #pragma warning restore IDE0079 // Remove unnecessary suppression 27 | } 28 | #endif 29 | } 30 | -------------------------------------------------------------------------------- /Refit/HttpRequestMessageProperties.cs: -------------------------------------------------------------------------------- 1 | namespace Refit 2 | { 3 | /// 4 | /// Contains Refit-defined properties on the HttpRequestMessage.Properties/Options 5 | /// 6 | public static class HttpRequestMessageOptions 7 | { 8 | /// 9 | /// Returns the of the top-level interface where the method was called from 10 | /// 11 | public static string InterfaceType { get; } = "Refit.InterfaceType"; 12 | 13 | /// 14 | /// Returns the of the top-level interface 15 | /// 16 | public static string RestMethodInfo { get; } = "Refit.RestMethodInfo"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Refit/JsonContentSerializer.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http; 2 | using System.Reflection; 3 | 4 | namespace Refit 5 | { 6 | /// 7 | /// JsonContentSerializer. 8 | /// 9 | /// 10 | [Obsolete( 11 | "Use NewtonsoftJsonContentSerializer in the Refit.Newtonsoft.Json package instead", 12 | true 13 | )] 14 | public class JsonContentSerializer : IHttpContentSerializer 15 | { 16 | /// 17 | /// Converts to httpcontent. 18 | /// 19 | /// Type of the object to serialize from. 20 | /// Object to serialize. 21 | /// 22 | /// that contains the serialized object. 23 | /// 24 | /// 25 | public HttpContent ToHttpContent(T item) => throw new NotImplementedException(); 26 | 27 | /// 28 | /// Deserializes an object of type from an object. 29 | /// 30 | /// Type of the object to serialize to. 31 | /// HttpContent object to deserialize. 32 | /// CancellationToken to abort the deserialization. 33 | /// 34 | /// The deserialized object of type . 35 | /// 36 | /// 37 | public Task FromHttpContentAsync( 38 | HttpContent content, 39 | CancellationToken cancellationToken = default 40 | ) => throw new NotImplementedException(); 41 | 42 | /// 43 | /// Calculates what the field name should be for the given property. This may be affected by custom attributes the serializer understands 44 | /// 45 | /// A PropertyInfo object. 46 | /// 47 | /// The calculated field name. 48 | /// 49 | /// 50 | public string GetFieldNameForProperty(PropertyInfo propertyInfo) => 51 | throw new NotImplementedException(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Refit/NameValueCollection.cs: -------------------------------------------------------------------------------- 1 | namespace System.Collections.Specialized 2 | { 3 | class NameValueCollection : Dictionary 4 | { 5 | public string[] AllKeys => Keys.ToArray(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Refit/ProblemDetails.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Refit 4 | { 5 | /// 6 | /// The object representing the details about a ValidationException caught by a service implementing RFC 7807. 7 | /// 8 | public class ProblemDetails 9 | { 10 | /// 11 | /// Collection of resulting errors for the request. 12 | /// 13 | public Dictionary Errors { get; set; } = []; 14 | 15 | /// 16 | /// Collection of ProblemDetails extensions 17 | /// 18 | [JsonExtensionData] 19 | public IDictionary Extensions { get; set; } = 20 | new Dictionary(StringComparer.Ordinal); 21 | 22 | /// 23 | /// A URI reference that identifies the problem type. 24 | /// 25 | public string? Type { get; set; } = "about:blank"; 26 | 27 | /// 28 | /// A short, human-readable summary of the problem type. 29 | /// 30 | public string? Title { get; set; } 31 | 32 | /// 33 | /// The HTTP status code generated by the origin server for this occurrence of the problem. 34 | /// 35 | public int Status { get; set; } 36 | 37 | /// 38 | /// A human-readable explanation specific to this occurrence of the problem. 39 | /// 40 | public string? Detail { get; set; } 41 | 42 | /// 43 | /// A URI reference that identifies the specific occurrence of the problem. 44 | /// 45 | public string? Instance { get; set; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Refit/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("Refit.Tests")] 4 | // "Refit.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009dc017250415a0d51fddb74de84257c388028f04893673ca5c8f9e7145aea2b11443cb49dd79386d2255179a79ec516466b621f77e43386e711b775f77bb0e4b217f8c208c054e5f515ae33ee76bac1b56cdc20e1c151cf026a9b7f8362f1963825e546e16b360dfc63fe670403c9d6152c24491dd5dfb9ff68fe102ef3e1aed" 5 | // )] 6 | [assembly: InternalsVisibleTo("Refit.HttpClientFactory")] 7 | // "Refit.HttpClientFactory, PublicKey=00240000048000009400000006020000002400005253413100040000010001009dc017250415a0d51fddb74de84257c388028f04893673ca5c8f9e7145aea2b11443cb49dd79386d2255179a79ec516466b621f77e43386e711b775f77bb0e4b217f8c208c054e5f515ae33ee76bac1b56cdc20e1c151cf026a9b7f8362f1963825e546e16b360dfc63fe670403c9d6152c24491dd5dfb9ff68fe102ef3e1aed" 8 | // )] 9 | [assembly: InternalsVisibleTo("Refit.Newtonsoft.Json")] 10 | // "Refit.Newtonsoft.Json, PublicKey=00240000048000009400000006020000002400005253413100040000010001009dc017250415a0d51fddb74de84257c388028f04893673ca5c8f9e7145aea2b11443cb49dd79386d2255179a79ec516466b621f77e43386e711b775f77bb0e4b217f8c208c054e5f515ae33ee76bac1b56cdc20e1c151cf026a9b7f8362f1963825e546e16b360dfc63fe670403c9d6152c24491dd5dfb9ff68fe102ef3e1aed" 11 | // )] 12 | [assembly: InternalsVisibleTo("Refit.Xml")] 13 | // "Refit.Xml, PublicKey=00240000048000009400000006020000002400005253413100040000010001009dc017250415a0d51fddb74de84257c388028f04893673ca5c8f9e7145aea2b11443cb49dd79386d2255179a79ec516466b621f77e43386e711b775f77bb0e4b217f8c208c054e5f515ae33ee76bac1b56cdc20e1c151cf026a9b7f8362f1963825e546e16b360dfc63fe670403c9d6152c24491dd5dfb9ff68fe102ef3e1aed" 14 | // )] 15 | -------------------------------------------------------------------------------- /Refit/Refit.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Refit ($(TargetFramework)) 5 | $(RefitTargets) 6 | true 7 | 8 | enable 9 | 10 | 11 | true 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Refit/RequestBuilderFactory.cs: -------------------------------------------------------------------------------- 1 | namespace Refit 2 | { 3 | interface IRequestBuilderFactory 4 | { 5 | IRequestBuilder Create(RefitSettings? settings); 6 | IRequestBuilder Create(Type refitInterfaceType, RefitSettings? settings); 7 | } 8 | 9 | class RequestBuilderFactory : IRequestBuilderFactory 10 | { 11 | public IRequestBuilder Create(RefitSettings? settings = null) 12 | { 13 | return new CachedRequestBuilderImplementation( 14 | new RequestBuilderImplementation(settings) 15 | ); 16 | } 17 | 18 | public IRequestBuilder Create(Type refitInterfaceType, RefitSettings? settings = null) 19 | { 20 | return new CachedRequestBuilderImplementation( 21 | new RequestBuilderImplementation(refitInterfaceType, settings) 22 | ); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Refit/RequestBuilderImplementation.TaskToObservable.cs: -------------------------------------------------------------------------------- 1 | namespace Refit 2 | { 3 | partial class RequestBuilderImplementation 4 | { 5 | sealed class TaskToObservable : IObservable 6 | { 7 | readonly Func> taskFactory; 8 | 9 | public TaskToObservable(Func> taskFactory) 10 | { 11 | this.taskFactory = taskFactory; 12 | } 13 | 14 | public IDisposable Subscribe(IObserver observer) 15 | { 16 | var cts = new CancellationTokenSource(); 17 | #pragma warning disable VSTHRD110 // Observe result of async calls 18 | taskFactory(cts.Token) 19 | .ContinueWith( 20 | t => 21 | { 22 | if (cts.IsCancellationRequested) 23 | return; 24 | 25 | ToObservableDone(t, observer); 26 | }, 27 | TaskScheduler.Default 28 | ); 29 | 30 | #pragma warning restore VSTHRD110 // Observe result of async calls 31 | 32 | return new AnonymousDisposable(cts.Cancel); 33 | } 34 | 35 | static void ToObservableDone(Task task, IObserver subject) 36 | { 37 | switch (task.Status) 38 | { 39 | case TaskStatus.RanToCompletion: 40 | #pragma warning disable VSTHRD002 // Avoid problematic synchronous waits 41 | subject.OnNext(task.Result); 42 | #pragma warning restore VSTHRD002 // Avoid problematic synchronous waits 43 | subject.OnCompleted(); 44 | break; 45 | case TaskStatus.Faulted: 46 | subject.OnError(task.Exception!.InnerException!); 47 | break; 48 | case TaskStatus.Canceled: 49 | subject.OnError(new TaskCanceledException(task)); 50 | break; 51 | } 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Refit/ValidationApiException.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | 3 | namespace Refit 4 | { 5 | /// 6 | /// An ApiException that is raised according to RFC 7807, which contains problem details for validation exceptions. 7 | /// 8 | [Serializable] 9 | public class ValidationApiException : ApiException 10 | { 11 | static readonly JsonSerializerOptions SerializerOptions = new(); 12 | 13 | static ValidationApiException() 14 | { 15 | SerializerOptions.PropertyNameCaseInsensitive = true; 16 | SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; 17 | SerializerOptions.Converters.Add(new ObjectToInferredTypesConverter()); 18 | } 19 | 20 | ValidationApiException(ApiException apiException) 21 | : base( 22 | apiException.RequestMessage, 23 | apiException.HttpMethod, 24 | apiException.Content, 25 | apiException.StatusCode, 26 | apiException.ReasonPhrase, 27 | apiException.Headers, 28 | apiException.RefitSettings 29 | ) { } 30 | 31 | /// 32 | /// Creates a new instance of a ValidationException from an existing ApiException. 33 | /// 34 | /// An instance of an ApiException to use to build a ValidationException. 35 | /// ValidationApiException 36 | public static ValidationApiException Create(ApiException exception) 37 | { 38 | if (exception is null) 39 | throw new ArgumentNullException(nameof(exception)); 40 | if (string.IsNullOrWhiteSpace(exception.Content)) 41 | throw new ArgumentException( 42 | "Content must be an 'application/problem+json' compliant json string." 43 | ); 44 | 45 | var ex = new ValidationApiException(exception); 46 | 47 | if (!string.IsNullOrWhiteSpace(exception.Content)) 48 | { 49 | ex.Content = JsonSerializer.Deserialize( 50 | exception.Content!, 51 | SerializerOptions 52 | ); 53 | } 54 | 55 | return ex; 56 | } 57 | 58 | /// 59 | /// The problem details of the RFC 7807 validation exception. 60 | /// 61 | public new ProblemDetails? Content { get; private set; } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Refit/targets/refit.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Refit/targets/refit.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | $(RootNamespace) 10 | 11 | <_RefitMSBuildMinVersion>16.8.0 12 | 13 | 14 | 15 | 16 | 17 | <_RefitAnalyzer Include="@(Analyzer)" Condition="'%(Analyzer.NuGetPackageId)' == 'Refit'" /> 18 | 19 | 20 | 21 | 25 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 47 | 49 | 50 | 51 | 52 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | title: Refit 2 | description: The automatic type-safe REST library for Xamarin and .NET 3 | google_analytics: 4 | show_downloads: true 5 | theme: jekyll-theme-dinky 6 | 7 | gems: 8 | - jekyll-mentions 9 | -------------------------------------------------------------------------------- /buildtask.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reactiveui/refit/8a48c63a071bebd82758440352db5b58551bc94f/buildtask.snk -------------------------------------------------------------------------------- /config/filelist.txt: -------------------------------------------------------------------------------- 1 | **/Refit.* 2 | **/InterfaceStubGenerator.* -------------------------------------------------------------------------------- /config/signclient.json: -------------------------------------------------------------------------------- 1 | { 2 | "SignClient": { 3 | "AzureAd": { 4 | "AADInstance": "https://login.microsoftonline.com/", 5 | "ClientId": "c248d68a-ba6f-4aa9-8a68-71fe872063f8", 6 | "TenantId": "16076fdc-fcc1-4a15-b1ca-32c9a255900e" 7 | }, 8 | "Service": { 9 | "Url": "https://codesign.dotnetfoundation.org/", 10 | "ResourceId": "https://SignService/3c30251f-36f3-490b-a955-520addb85001" 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /refit_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reactiveui/refit/8a48c63a071bebd82758440352db5b58551bc94f/refit_logo.png -------------------------------------------------------------------------------- /samples/Meow.Common/Meow.Common.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/Meow.Common/Middleware/HttpClientDiagnosticsHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using Serilog; 6 | 7 | namespace HttpClientDiagnostics 8 | { 9 | [DebuggerStepThrough] 10 | public class HttpClientDiagnosticsHandler : DelegatingHandler 11 | { 12 | public HttpClientDiagnosticsHandler(HttpMessageHandler innerHandler) 13 | : base(innerHandler) { } 14 | 15 | public HttpClientDiagnosticsHandler() { } 16 | 17 | protected override async Task SendAsync( 18 | HttpRequestMessage request, 19 | CancellationToken cancellationToken 20 | ) 21 | { 22 | var totalElapsedTime = Stopwatch.StartNew(); 23 | 24 | Log.Debug(string.Format("Request: {0}", request)); 25 | if (request.Content != null) 26 | { 27 | var content = await request.Content.ReadAsStringAsync().ConfigureAwait(false); 28 | Log.Debug(string.Format("Request Content: {0}", content)); 29 | } 30 | 31 | var responseElapsedTime = Stopwatch.StartNew(); 32 | var response = await base.SendAsync(request, cancellationToken); 33 | 34 | Log.Debug(string.Format("Response: {0}", response)); 35 | if (response.Content != null) 36 | { 37 | var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); 38 | Log.Debug(string.Format("Response Content: {0}", content)); 39 | } 40 | 41 | responseElapsedTime.Stop(); 42 | Log.Debug( 43 | string.Format( 44 | "Response elapsed time: {0} ms", 45 | responseElapsedTime.ElapsedMilliseconds 46 | ) 47 | ); 48 | 49 | totalElapsedTime.Stop(); 50 | Log.Debug( 51 | string.Format("Total elapsed time: {0} ms", totalElapsedTime.ElapsedMilliseconds) 52 | ); 53 | 54 | return response; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /samples/Meow.Common/Responses/SearchResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Meow.Responses 6 | { 7 | public class SearchResult 8 | { 9 | public Breed[] breeds { get; set; } 10 | public string id { get; set; } 11 | public string url { get; set; } 12 | public int width { get; set; } 13 | public int height { get; set; } 14 | } 15 | 16 | public class Breed 17 | { 18 | public Weight weight { get; set; } 19 | public string id { get; set; } 20 | public string name { get; set; } 21 | public string cfa_url { get; set; } 22 | public string vetstreet_url { get; set; } 23 | public string vcahospitals_url { get; set; } 24 | public string temperament { get; set; } 25 | public string origin { get; set; } 26 | public string country_codes { get; set; } 27 | public string country_code { get; set; } 28 | public string description { get; set; } 29 | public string life_span { get; set; } 30 | public int indoor { get; set; } 31 | public int lap { get; set; } 32 | public string alt_names { get; set; } 33 | public int adaptability { get; set; } 34 | public int affection_level { get; set; } 35 | public int child_friendly { get; set; } 36 | public int dog_friendly { get; set; } 37 | public int energy_level { get; set; } 38 | public int grooming { get; set; } 39 | public int health_issues { get; set; } 40 | public int intelligence { get; set; } 41 | public int shedding_level { get; set; } 42 | public int social_needs { get; set; } 43 | public int stranger_friendly { get; set; } 44 | public int vocalisation { get; set; } 45 | public int experimental { get; set; } 46 | public int hairless { get; set; } 47 | public int natural { get; set; } 48 | public int rare { get; set; } 49 | public int rex { get; set; } 50 | public int suppressed_tail { get; set; } 51 | public int short_legs { get; set; } 52 | public string wikipedia_url { get; set; } 53 | public int hypoallergenic { get; set; } 54 | } 55 | 56 | public class Weight 57 | { 58 | public string imperial { get; set; } 59 | public string metric { get; set; } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /samples/Meow.Common/Services/CatsService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Http; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using HttpClientDiagnostics; 7 | using Meow.Responses; 8 | using Refit; 9 | 10 | namespace Meow 11 | { 12 | public class CatsService 13 | { 14 | private readonly HttpClient _httpClient; 15 | private readonly ITheCatsAPI _theCatsApi; 16 | 17 | public CatsService(Uri baseUrl) 18 | { 19 | _httpClient = new HttpClient(new HttpClientDiagnosticsHandler(new HttpClientHandler())) 20 | { 21 | BaseAddress = baseUrl 22 | }; 23 | _theCatsApi = RestService.For(_httpClient); 24 | } 25 | 26 | public async Task> Search(string breed) 27 | { 28 | return await _theCatsApi.Search(breed).ConfigureAwait(false); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /samples/Meow.Common/Services/ITheCatsAPI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using Meow.Responses; 6 | using Refit; 7 | 8 | namespace Meow 9 | { 10 | [Headers("x-api-key: b95bfb30-55bc-4327-bb8b-35d740f70051")] 11 | public interface ITheCatsAPI 12 | { 13 | [Get("/v1/images/search")] 14 | Task> Search([AliasAs("q")] string breedIdentifier); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /samples/Meow.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28711.60 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Meow", "Meow\Meow.csproj", "{F89AADAA-1C9E-4125-B6CF-9AD1E6CD94F1}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Meow.Common", "Meow.Common\Meow.Common.csproj", "{270B1965-B666-4360-AE18-D129DFE3CB9F}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F89AADAA-1C9E-4125-B6CF-9AD1E6CD94F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {F89AADAA-1C9E-4125-B6CF-9AD1E6CD94F1}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {F89AADAA-1C9E-4125-B6CF-9AD1E6CD94F1}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {F89AADAA-1C9E-4125-B6CF-9AD1E6CD94F1}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {270B1965-B666-4360-AE18-D129DFE3CB9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {270B1965-B666-4360-AE18-D129DFE3CB9F}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {270B1965-B666-4360-AE18-D129DFE3CB9F}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {270B1965-B666-4360-AE18-D129DFE3CB9F}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {DCB37AC1-9A6D-4947-AA9D-61B0A757E0D6} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /samples/Meow/Meow.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /samples/Meow/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Serilog; 4 | 5 | namespace Meow 6 | { 7 | class Program 8 | { 9 | static async Task Main(string[] args) 10 | { 11 | Log.Logger = new LoggerConfiguration() 12 | .WriteTo.Console() 13 | .MinimumLevel.Verbose() 14 | .CreateLogger(); 15 | 16 | var service = new CatsService(new Uri("https://api.thecatapi.com")); 17 | var results = await service.Search("bengal"); 18 | 19 | Log.Debug("{results}", results); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /samples/SampleWithLocalAPIs.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.852 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryWithSDKandRefitService", "sampleUsngLocalApi\LibraryWithSDKandRefitService\LibraryWithSDKandRefitService.csproj", "{97A0AF3F-830B-4067-BFC3-0BA7AC6851E7}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestApiForTest", "sampleUsngLocalApi\RestApiforTest\RestApiForTest.csproj", "{1A2E3E56-878E-4D2D-89D3-626DB0825120}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleSampleUsingLocalApi", "sampleUsngLocalApi\ConsoleApplication\ConsoleSampleUsingLocalApi.csproj", "{D7F3EC64-7473-4FD3-AB05-D7BE55009BE3}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {97A0AF3F-830B-4067-BFC3-0BA7AC6851E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {97A0AF3F-830B-4067-BFC3-0BA7AC6851E7}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {97A0AF3F-830B-4067-BFC3-0BA7AC6851E7}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {97A0AF3F-830B-4067-BFC3-0BA7AC6851E7}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {1A2E3E56-878E-4D2D-89D3-626DB0825120}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {1A2E3E56-878E-4D2D-89D3-626DB0825120}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {1A2E3E56-878E-4D2D-89D3-626DB0825120}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {1A2E3E56-878E-4D2D-89D3-626DB0825120}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {D7F3EC64-7473-4FD3-AB05-D7BE55009BE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {D7F3EC64-7473-4FD3-AB05-D7BE55009BE3}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {D7F3EC64-7473-4FD3-AB05-D7BE55009BE3}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {D7F3EC64-7473-4FD3-AB05-D7BE55009BE3}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {ACEEE495-B3D1-4788-9EE2-C33449109B85} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /samples/sampleUsngLocalApi/ConsoleApplication/ConsoleSampleUsingLocalApi.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /samples/sampleUsngLocalApi/ConsoleApplication/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Net.Http; 4 | using System.Net.Http.Headers; 5 | using LibraryWithSDKandRefitService; 6 | using Refit; 7 | 8 | namespace ConsoleSampleUsingLocalApi 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | Console.WriteLine("Hello World!"); 15 | HttpClient _client = new HttpClient { BaseAddress = new Uri("http://localhost:61868") }; 16 | IRestService _restApiService = RestService.For(_client); 17 | Console.WriteLine( 18 | "Enter from the following numbers to access the APIs,\n1 for get ,\n2 for get with argument, \n3 for post,\n4 for put, \n5 for Delete \n" 19 | ); 20 | while (true) 21 | { 22 | int choice = Int32.Parse(Console.ReadLine() ?? "6"); 23 | switch (choice) 24 | { 25 | case 1: 26 | var result1 = _restApiService.GetWithNoParameter().Result; 27 | Console.WriteLine(result1); 28 | break; 29 | case 2: 30 | var result2 = _restApiService.GetWithParameter(4).Result; 31 | Console.WriteLine(result2); 32 | break; 33 | case 3: 34 | var result3 = _restApiService.PostWithTestObject(new ModelForTest()).Result; 35 | Console.WriteLine(result3); 36 | break; 37 | case 4: 38 | var result4 = _restApiService 39 | .PutWithParameters(4, new ModelForTest()) 40 | .Result; 41 | Console.WriteLine(result4); 42 | break; 43 | case 5: 44 | var result5 = _restApiService.DeleteWithParameters(5).Result; 45 | Console.WriteLine(result5); 46 | break; 47 | default: 48 | Console.WriteLine("Bhai Please Enter valid if you are really serious"); 49 | break; 50 | } 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /samples/sampleUsngLocalApi/LibraryWithSDKandRefitService/IRestService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using Refit; 4 | 5 | namespace LibraryWithSDKandRefitService 6 | { 7 | public interface IRestService 8 | { 9 | [Get("/api/values")] 10 | Task GetWithNoParameter(); 11 | 12 | [Get("/api/values/{id}")] 13 | Task GetWithParameter([AliasAs("id")] int id); 14 | 15 | [Post("/api/values")] 16 | Task PostWithTestObject([Body] ModelForTest modelObject); 17 | 18 | [Put("/api/values/{id}")] 19 | Task PutWithParameters([AliasAs("id")] int id, [Body] ModelForTest modelObject); 20 | 21 | [Delete("/api/values/{id}")] 22 | Task DeleteWithParameters([AliasAs("id")] int id); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /samples/sampleUsngLocalApi/LibraryWithSDKandRefitService/LibraryWithSDKandRefitService.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /samples/sampleUsngLocalApi/LibraryWithSDKandRefitService/ModelForTest.cs: -------------------------------------------------------------------------------- 1 | namespace LibraryWithSDKandRefitService 2 | { 3 | public class ModelForTest 4 | { 5 | public string TestVariable { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /samples/sampleUsngLocalApi/RestApiforTest/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using LibraryWithSDKandRefitService; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace RestApiforTest.Controllers 6 | { 7 | [Route("api/[controller]")] 8 | [ApiController] 9 | public class ValuesController : ControllerBase 10 | { 11 | // GET api/values 12 | [HttpGet] 13 | public ActionResult Get() 14 | { 15 | return "Get Api with no argument was Called"; 16 | } 17 | 18 | // GET api/values/5 19 | [HttpGet("{id}")] 20 | public ActionResult Get(int id) 21 | { 22 | return "Get Api was called"; 23 | } 24 | 25 | // POST api/values 26 | [HttpPost] 27 | public ActionResult Post([FromBody] ModelForTest testObject) 28 | { 29 | return "Post Api was Called"; 30 | } 31 | 32 | // PUT api/values/5 33 | [HttpPut("{id}")] 34 | public ActionResult Put(int id, [FromBody] ModelForTest testObject) 35 | { 36 | return "Put Api was called"; 37 | } 38 | 39 | // DELETE api/values/5 40 | [HttpDelete("{id}")] 41 | public ActionResult Delete(int id) 42 | { 43 | return "Delete Api was Called"; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /samples/sampleUsngLocalApi/RestApiforTest/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace RestApiforTest 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args).UseStartup(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /samples/sampleUsngLocalApi/RestApiforTest/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:61868", 8 | "sslPort": 0 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "api/values", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "RestApiforTest": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "api/values", 24 | "applicationUrl": "http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /samples/sampleUsngLocalApi/RestApiforTest/RestApiForTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | InProcess 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /samples/sampleUsngLocalApi/RestApiforTest/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.DependencyInjection; 10 | using Microsoft.Extensions.Logging; 11 | using Microsoft.Extensions.Options; 12 | 13 | namespace RestApiforTest 14 | { 15 | public class Startup 16 | { 17 | public Startup(IConfiguration configuration) 18 | { 19 | Configuration = configuration; 20 | } 21 | 22 | public IConfiguration Configuration { get; } 23 | 24 | // This method gets called by the runtime. Use this method to add services to the container. 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); 28 | } 29 | 30 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 31 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 32 | { 33 | if (env.IsDevelopment()) 34 | { 35 | app.UseDeveloperExceptionPage(); 36 | } 37 | 38 | app.UseMvc(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /samples/sampleUsngLocalApi/RestApiforTest/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /samples/sampleUsngLocalApi/RestApiforTest/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /version.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "8.0.0", 3 | "publicReleaseRefSpec": [ 4 | "^refs/heads/main$", // we release out of main 5 | "^refs/heads/rel/v\\d+\\.\\d+" // we also release branches starting with vN.N 6 | ], 7 | "nugetPackageVersion":{ 8 | "semVer": 2 9 | } 10 | } 11 | --------------------------------------------------------------------------------