-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C sharp support #39
Open
DBMasterC
wants to merge
5
commits into
RicoSuter:master
Choose a base branch
from
DBMasterC:CSharpSupport
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
C sharp support #39
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9166b40
starting c# support.
DBMasterC 1b3924d
keep working on csharp liquid template
DBMasterC f35a60b
producing working c# clients
DBMasterC f6451b7
Change Actions to be Funcs and be Task-returning
DBMasterC 51b4b6a
Bump versions for PR
DBMasterC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace SigSpec.CodeGeneration.CSharp.Models | ||
{ | ||
public class FileModel | ||
{ | ||
public FileModel(IEnumerable<string> hubs, string @namespace) | ||
{ | ||
Hubs = hubs; | ||
Namespace = @namespace; | ||
} | ||
public string Namespace { get; set; } | ||
|
||
public IEnumerable<string> Hubs { get; } | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/SigSpec.CodeGeneration.CSharp/SigSpec.CodeGeneration.CSharp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="Templates\File.liquid" /> | ||
<None Remove="Templates\Hub.liquid" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Include="Templates\File.liquid" /> | ||
<EmbeddedResource Include="Templates\Hub.liquid" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="njsonschema.codegeneration" Version="10.3.1" /> | ||
<PackageReference Include="njsonschema.codegeneration.csharp" Version="10.3.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\SigSpec.CodeGeneration\SigSpec.CodeGeneration.csproj" /> | ||
<ProjectReference Include="..\SigSpec.Core\SigSpec.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
56 changes: 56 additions & 0 deletions
56
src/SigSpec.CodeGeneration.CSharp/SigSpecToCSharpGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using NJsonSchema.CodeGeneration; | ||
using NJsonSchema.CodeGeneration.CSharp; | ||
using SigSpec.CodeGeneration.CSharp.Models; | ||
using SigSpec.CodeGeneration.Models; | ||
using SigSpec.Core; | ||
|
||
namespace SigSpec.CodeGeneration.CSharp | ||
{ | ||
public class SigSpecToCSharpGenerator | ||
{ | ||
private readonly SigSpecToCSharpGeneratorSettings _settings; | ||
|
||
public SigSpecToCSharpGenerator(SigSpecToCSharpGeneratorSettings settings) | ||
{ | ||
_settings = settings; | ||
} | ||
|
||
public IEnumerable<CodeArtifact> GenerateArtifacts(SigSpecDocument document) | ||
{ | ||
var resolver = new CSharpTypeResolver(_settings.CSharpGeneratorSettings); | ||
resolver.RegisterSchemaDefinitions(document.Definitions); | ||
|
||
var artifacts = new List<CodeArtifact>(); | ||
foreach (var hub in document.Hubs) | ||
{ | ||
var hubModel = new HubModel(hub.Key, hub.Value, resolver); | ||
var template = _settings.CSharpGeneratorSettings.TemplateFactory.CreateTemplate("CSharp", "Hub", hubModel); | ||
artifacts.Add(new CodeArtifact(hubModel.Name, CodeArtifactType.Class, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Client, template.Render())); | ||
} | ||
|
||
if (_settings.GenerateDtoTypes) | ||
{ | ||
var generator = new NJsonSchema.CodeGeneration.CSharp.CSharpGenerator(document, _settings.CSharpGeneratorSettings, resolver); //TypeScriptGenerator(document, _settings.TypeScriptGeneratorSettings, resolver); | ||
var types = generator.GenerateTypes(); | ||
return artifacts.Concat(types); | ||
} | ||
else | ||
{ | ||
var generator = new CSharpGenerator(document, _settings.CSharpGeneratorSettings, resolver); | ||
return artifacts.Concat(generator.GenerateTypes()); | ||
} | ||
} | ||
|
||
public string GenerateClients(SigSpecDocument document) | ||
{ | ||
var artifacts = GenerateArtifacts(document); | ||
|
||
var fileModel = new FileModel(artifacts.Select(a => a.Code), _settings.CSharpGeneratorSettings.Namespace); | ||
var fileTemplate = _settings.CSharpGeneratorSettings.TemplateFactory.CreateTemplate("CSharp", "File", fileModel); | ||
|
||
return fileTemplate.Render(); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/SigSpec.CodeGeneration.CSharp/SigSpecToCSharpGeneratorSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Reflection; | ||
using NJsonSchema.CodeGeneration.CSharp; | ||
|
||
namespace SigSpec.CodeGeneration.CSharp | ||
{ | ||
public class SigSpecToCSharpGeneratorSettings : SigSpecToCSharpGeneratorSettingsBase | ||
{ | ||
public SigSpecToCSharpGeneratorSettings() | ||
: base(new CSharpGeneratorSettings()) | ||
{ | ||
CodeGeneratorSettings.TemplateFactory = new DefaultTemplateFactory(CSharpGeneratorSettings, new[] | ||
{ | ||
typeof(CSharpGeneratorSettings).GetTypeInfo().Assembly, | ||
typeof(SigSpecToCSharpGeneratorSettingsBase).GetTypeInfo().Assembly | ||
}); | ||
//TypeScriptGeneratorSettings.TypeStyle = TypeScriptTypeStyle.Interface; | ||
//CodeGeneratorSettings.TemplateFactory = new DefaultTemplateFactory(TypeScriptGeneratorSettings, new[] | ||
//{ | ||
// typeof(TypeScriptGeneratorSettings).GetTypeInfo().Assembly, | ||
// typeof(SigSpecToTypeScriptGeneratorSettingsBase).GetTypeInfo().Assembly, | ||
//}); | ||
|
||
} | ||
|
||
public CSharpGeneratorSettings CSharpGeneratorSettings => (CSharpGeneratorSettings)CodeGeneratorSettings; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace {{ Namespace }} | ||
{ | ||
using System.Threading.Tasks; | ||
using System; | ||
using Microsoft.AspNetCore.SignalR.Client; | ||
|
||
{% for hub in Hubs -%} | ||
{{ hub }} | ||
{% endfor -%} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
public class {{ Name }}HubClient { | ||
private readonly HubConnection _connection; | ||
|
||
public {{Name}}HubClient(HubConnection connection) { | ||
_connection = connection; | ||
} | ||
{% for operation in Callbacks -%} | ||
public delegate Task On{{ operation.Name }}({% for parameter in operation.Parameters %}{{ parameter.Type }} {{ parameter.Name }}{% if forloop.last == false %}, {% endif %}{% endfor %}); | ||
{% if operation.Parameters.size == 0 %} | ||
public IDisposable RegisterFor{{ operation.Name }}(On{{ operation.Name }} callback) | ||
{ | ||
return _connection.On("{{ operation.Name }}", callback.Invoke); | ||
} | ||
public IDisposable RegisterFor{{ operation.Name }}(Func<Task> callback) | ||
{ | ||
return _connection.On("{{ operation.Name }}", callback); | ||
} | ||
{% else %} | ||
public IDisposable RegisterFor{{ operation.Name }}(On{{ operation.Name }} callback) | ||
{ | ||
return _connection.On<{% for parameter in operation.Parameters %}{{ parameter.Type }}{% if forloop.last == false %}, {% endif %}{% endfor %}>("{{ operation.Name }}", callback.Invoke); | ||
} | ||
public IDisposable RegisterFor{{ operation.Name }}(Func<{% for parameter in operation.Parameters %}{{ parameter.Type }}{% if forloop.last == false %}, {% endif %}{% endfor %}, Task> callback) | ||
{ | ||
return _connection.On("{{ operation.Name }}", callback); | ||
} | ||
{% endif %} | ||
{% endfor -%} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/SigSpec.CodeGeneration/SigSpecToCSharpGeneratorSettingsBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using NJsonSchema.CodeGeneration; | ||
|
||
namespace SigSpec.CodeGeneration | ||
{ | ||
public class SigSpecToCSharpGeneratorSettingsBase : ClientGeneratorBaseSettings | ||
{ | ||
public SigSpecToCSharpGeneratorSettingsBase(CodeGeneratorSettingsBase codeGeneratorSettings) | ||
{ | ||
CodeGeneratorSettings = codeGeneratorSettings; | ||
} | ||
|
||
protected CodeGeneratorSettingsBase CodeGeneratorSettings { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you maybe keep the ts code here (commented) so we have both samples here?