Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.1;net46</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
<RootNamespace>Refit.Generator.App</RootNamespace>
</PropertyGroup>

Expand Down
8 changes: 4 additions & 4 deletions InterfaceStubGenerator.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static int Main(string[] args)
{
var retryCount = 3;

retry:
retry:
var file = default(FileStream);

// NB: Parallel build weirdness means that we might get >1 person
Expand All @@ -91,7 +91,7 @@ static int Main(string[] args)
goto retry;
}

using(var sw = new StreamWriter(file, Encoding.UTF8))
using (var sw = new StreamWriter(file, Encoding.UTF8))
{
sw.WriteLine(template);
}
Expand All @@ -103,9 +103,9 @@ static int Main(string[] args)

static class ConcatExtension
{
public static IEnumerable<T> Concat<T>(this IEnumerable<T> This, params IEnumerable<T>[] others)
public static IEnumerable<T> Concat<T>(this IEnumerable<T> @this, params IEnumerable<T>[] others)
{
foreach (var t in This)
foreach (var t in @this)
{
yield return t;
}
Expand Down
8 changes: 4 additions & 4 deletions InterfaceStubGenerator.BuildTasks/ContextAwareTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Linq;
using System.Threading.Tasks;
using Task = Microsoft.Build.Utilities.Task;
#if NETCOREAPP2_0
#if NETCOREAPP2_1
using Microsoft.Build.Framework;
using System.Runtime.Loader;
#endif
Expand All @@ -20,7 +20,7 @@ public abstract class ContextAwareTask : Task

public override bool Execute()
{
#if NETCOREAPP2_0
#if NETCOREAPP2_1
var taskAssemblyPath = new Uri(GetType().GetTypeInfo().Assembly.CodeBase).LocalPath;
var ctxt = new CustomAssemblyLoader(this);
var inContextAssembly = ctxt.LoadFromAssemblyPath(taskAssemblyPath);
Expand All @@ -43,7 +43,7 @@ public override bool Execute()
}

var executeInnerMethod = innerTaskType.GetMethod(nameof(ExecuteInner), BindingFlags.Instance | BindingFlags.NonPublic);
bool result = (bool)executeInnerMethod.Invoke(innerTask, new object[0]);
var result = (bool)executeInnerMethod.Invoke(innerTask, new object[0]);

foreach (var propertyPair in outputPropertiesMap)
{
Expand All @@ -70,7 +70,7 @@ public override bool Execute()

protected abstract bool ExecuteInner();

#if NETCOREAPP2_0
#if NETCOREAPP2_1
private class CustomAssemblyLoader : AssemblyLoadContext
{
private readonly ContextAwareTask loaderTask;
Expand Down
4 changes: 2 additions & 2 deletions InterfaceStubGenerator.BuildTasks/GenerateStubsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected override bool ExecuteInner()
{
var retryCount = 3;

retry:
retry:

FileStream file;

Expand All @@ -100,7 +100,7 @@ protected override bool ExecuteInner()
goto retry;
}

using(var sw = new StreamWriter(file, Encoding.UTF8))
using (var sw = new StreamWriter(file, Encoding.UTF8))
{
sw.WriteLine(template);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp2.1</TargetFrameworks>
<RootNamespace>Refit.Generator.Tasks</RootNamespace>
<AssemblyOriginatorKeyFile>..\buildtask.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
</PropertyGroup>

<ItemGroup>
<PackageReference Condition="'$(TargetFramework)' == 'net46' " Include="Microsoft.Build.Tasks.Core" Version="14.3" PrivateAssets="all" />
<PackageReference Condition="'$(TargetFramework)' == 'netcoreapp2.0' " Include="Microsoft.Build.Tasks.Core" Version="15.1.548" PrivateAssets="all" />
<PackageReference Condition="'$(TargetFramework)' == 'net461' " Include="Microsoft.Build.Tasks.Core" Version="14.3" PrivateAssets="all" />
<PackageReference Condition="'$(TargetFramework)' == 'netcoreapp2.1' " Include="Microsoft.Build.Tasks.Core" Version="15.1.548" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
36 changes: 17 additions & 19 deletions InterfaceStubGenerator.Core/GeneratedInterfaceStubTemplate.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
{{#UsingList}}
using {{Item}};
{{/UsingList}}
Expand All @@ -18,7 +15,7 @@ using {{Item}};
#pragma warning disable
namespace {{RefitInternalNamespace}}RefitInternalGenerated
{
[ExcludeFromCodeCoverage]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[AttributeUsage (AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate)]
sealed class PreserveAttribute : Attribute
{
Expand All @@ -39,17 +36,18 @@ namespace {{Namespace}}
using {{RefitInternalNamespace}}RefitInternalGenerated;

/// <inheritdoc />
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Diagnostics.DebuggerNonUserCode]
[Preserve]
[Obfuscation(Exclude=true)]
[global::System.Reflection.Obfuscation(Exclude=true)]
partial class AutoGenerated{{GeneratedClassSuffix}}{{#TypeParameters}}<{{.}}>
{{/TypeParameters}} : {{InterfaceName}}{{#TypeParameters}}<{{.}}>
{{/TypeParameters}}
{{#ConstraintClauses}}
{{.}}
{{/ConstraintClauses}}
{

{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly IRequestBuilder requestBuilder;
Expand All @@ -60,26 +58,26 @@ namespace {{Namespace}}
Client = client;
this.requestBuilder = requestBuilder;
}
{{#MethodList}}

{{#MethodList}}
/// <inheritdoc />
public virtual {{ReturnType}} {{Name}}{{#MethodTypeParameters}}<{{.}}>{{/MethodTypeParameters}}({{ArgumentListWithTypes}})
{{#MethodConstraintClauses}}
public virtual {{ReturnType}} {{Name}}{{#MethodTypeParameters}}<{{.}}>
{{/MethodTypeParameters}}({{ArgumentListWithTypes}})
{{#MethodConstraintClauses}}
{{.}}
{{/MethodConstraintClauses}}
{{/MethodConstraintClauses}}
{
{{#IsRefitMethod}}
{{#IsRefitMethod}}
var arguments = new object[] { {{ArgumentList}} };
var func = requestBuilder.BuildRestResultFuncForMethod("{{Name}}", new Type[] { {{ArgumentTypesList}} }{{#MethodTypeParameterList}}, new Type[] { {{.}} }{{/MethodTypeParameterList}});
return ({{ReturnType}})func(Client, arguments);
{{/IsRefitMethod}}
{{^IsRefitMethod}}
{{/IsRefitMethod}}
{{^IsRefitMethod}}
throw new NotImplementedException("Either this method has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument.");
{{/IsRefitMethod}}
{{/IsRefitMethod}}
}

{{/MethodList}}
{{/MethodList}}
}
}

{{/ClassList}}
{{/ClassList}}
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<RootNamespace>Refit.Generator</RootNamespace>
<IsPackable>false</IsPackable>
<AssemblyOriginatorKeyFile>..\buildtask.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.8.2" />
<PackageReference Include="Nustache" Version="1.16.0.8" />
<Reference Condition="'$(TargetFramework)' == 'net46' " Include="System.Net.Http" />


<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.0.0-beta3-final" />
<PackageReference Include="Nustache" Version="1.16.0.8" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions InterfaceStubGenerator.Core/InterfaceStubGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Refit.Generator
// What if the Interface is in another module? (since we copy usings, should be fine)
public class InterfaceStubGenerator
{
static readonly HashSet<string> httpMethodAttributeNames = new HashSet<string>(
static readonly HashSet<string> HttpMethodAttributeNames = new HashSet<string>(
new[] { "Get", "Head", "Post", "Put", "Delete", "Patch", "Options" }
.SelectMany(x => new[] { "{0}", "{0}Attribute" }.Select(f => string.Format(f, x))));

Expand Down Expand Up @@ -210,7 +210,7 @@ public bool HasRefitHttpMethodAttribute(MethodDeclarationSyntax method)
// but what if somebody is dumb and uses a constant?
// Could be turtles all the way down.
return method.AttributeLists.SelectMany(a => a.Attributes)
.Any(a => httpMethodAttributeNames.Contains(a.Name.ToString().Split('.').Last()) &&
.Any(a => HttpMethodAttributeNames.Contains(a.Name.ToString().Split('.').Last()) &&
a.ArgumentList.Arguments.Count == 1 &&
a.ArgumentList.Arguments[0].Expression.Kind() == SyntaxKind.StringLiteralExpression);
}
Expand Down
11 changes: 7 additions & 4 deletions Refit.Tests/DeliminatorSeparatedPropertyNamesContractResolver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using System;
using System.Globalization;
Expand All @@ -20,16 +20,19 @@ protected override string ResolvePropertyName(string propertyName)
var parts = new List<string>();
var currentWord = new StringBuilder();

foreach (var c in propertyName.ToCharArray()) {
if (Char.IsUpper(c) && currentWord.Length > 0) {
foreach (var c in propertyName.ToCharArray())
{
if (Char.IsUpper(c) && currentWord.Length > 0)
{
parts.Add(currentWord.ToString());
currentWord.Clear();
}

currentWord.Append(char.ToLower(c));
}

if (currentWord.Length > 0) {
if (currentWord.Length > 0)
{
parts.Add(currentWord.ToString());
}

Expand Down
4 changes: 2 additions & 2 deletions Refit.Tests/GitHubApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public interface IGitHubApi

[Get("/users/{userName}")]
IObservable<User> GetUserCamelCase(string userName);

[Get("/orgs/{orgname}/members")]
Task<List<User>> GetOrgMembers(string orgName);

Expand Down Expand Up @@ -106,7 +106,7 @@ public interface INestedGitHubApi

[Get("/users/{userName}")]
IObservable<User> GetUserCamelCase(string userName);

[Get("/orgs/{orgname}/members")]
Task<List<User>> GetOrgMembers(string orgName);

Expand Down
2 changes: 1 addition & 1 deletion Refit.Tests/IServiceWithoutNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface IServiceWithoutNamespace
{
[Get("/")]
Task GetRoot();

[Post("/")]
Task PostRoot();
}
12 changes: 6 additions & 6 deletions Refit.Tests/InterfaceStubGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void GenerateClassInfoForInterfaceSmokeTest()
Assert.Equal("IGitHubApi", result.InterfaceName);
Assert.Equal("IGitHubApi", result.GeneratedClassSuffix);
}

[Fact]
public void GenerateClassInfoForNestedInterfaceSmokeTest()
{
Expand All @@ -104,14 +104,14 @@ public void GenerateClassInfoForNestedInterfaceSmokeTest()
.First(x => x.Identifier.ValueText == "INestedGitHubApi");

var result = fixture.GenerateClassInfoForInterface(input);
Assert.Equal("TestNested.INestedGitHubApi",result.InterfaceName);
Assert.Equal("TestNestedINestedGitHubApi",result.GeneratedClassSuffix);

Assert.Equal("TestNested.INestedGitHubApi", result.InterfaceName);
Assert.Equal("TestNestedINestedGitHubApi", result.GeneratedClassSuffix);
Assert.Equal(8, result.MethodList.Count);
Assert.Equal("GetUser", result.MethodList[0].Name);
Assert.Equal("string userName", result.MethodList[0].ArgumentListWithTypes);
}

[Fact]
public void GenerateTemplateInfoForInterfaceListSmokeTest()
{
Expand Down Expand Up @@ -169,7 +169,7 @@ public interface IAmARefitInterfaceButNobodyUsesMe
[Get(ThisIsDumbButMightHappen.PeopleDoWeirdStuff)]
Task NoConstantsAllowed();

[Get ("spaces-shouldnt-break-me")]
[Get("spaces-shouldnt-break-me")]
Task SpacesShouldntBreakMe();

// We don't need an explicit test for this because if it isn't supported we can't compile
Expand Down
6 changes: 3 additions & 3 deletions Refit.Tests/MethodOverloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public async Task GenericMethodOverloadTest2()

mockHttp.Expect(HttpMethod.Get, "https://httpbin.org/status/403")
.Respond(HttpStatusCode.Forbidden);


var fixture = RestService.For<IUseOverloadedGenericMethods<HttpBinGet, string, int>>("https://httpbin.org/", settings);

Expand Down Expand Up @@ -197,7 +197,7 @@ public async Task GenericMethodOverloadTest6()
.Respond("application/json", "generic-output");

var fixture = RestService.For<IUseOverloadedGenericMethods<HttpBinGet, string, int>>("https://httpbin.org/", settings);

var result = await fixture.Get<string, int>(99);

Assert.Equal("generic-output", result);
Expand All @@ -224,7 +224,7 @@ public async Task GenericMethodOverloadTest7()

var fixture = RestService.For<IUseOverloadedGenericMethods<HttpBinGet, string, int>>("https://httpbin.org/", settings);

await fixture.Get<string, int>("str", 3);
await fixture.Get<string, int>("str", 3);

mockHttp.VerifyNoOutstandingExpectation();
}
Expand Down
Loading