-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor: Add support for combining callback parameters
- Loading branch information
1 parent
0ed46f0
commit b79df43
Showing
21 changed files
with
361 additions
and
58 deletions.
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
34 changes: 34 additions & 0 deletions
34
...or/CodeGeneration/CodeConverterFactories/CombinedCallbackParameterCodeConverterFactory.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,34 @@ | ||
using System; | ||
using WebExtensions.Net.Generator.CodeGeneration.CodeConverters; | ||
using WebExtensions.Net.Generator.Models.ClrTypes; | ||
|
||
namespace WebExtensions.Net.Generator.CodeGeneration.CodeConverterFactories | ||
{ | ||
public class CombinedCallbackParameterCodeConverterFactory : ICodeConverterFactory | ||
{ | ||
public void AddInterfaceConvertersToCodeFile(ClrTypeInfo clrTypeInfo, CodeFile codeFile) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void AddConvertersToCodeFile(ClrTypeInfo clrTypeInfo, CodeFile codeFile) | ||
{ | ||
codeFile.UsingNamespaces.Add("System.Text.Json.Serialization"); | ||
codeFile.Comments.Add(new CommentCodeConverter("Combined Callback Parameter Class")); | ||
codeFile.Comments.Add(new CommentSummaryCodeConverter(clrTypeInfo.Description)); | ||
|
||
if (clrTypeInfo.IsObsolete) | ||
{ | ||
codeFile.Attributes.Add(new AttributeObsoleteCodeConverter(clrTypeInfo.ObsoleteMessage)); | ||
} | ||
codeFile.Attributes.Add(new AttributeCodeConverter($"JsonConverter(typeof(CombinedCallbackParameterJsonConverter<{clrTypeInfo.CSharpName}>))")); | ||
|
||
codeFile.Constructors.Add(new CombinedCallbackParameterConstructorCodeConverter(clrTypeInfo.CSharpName, clrTypeInfo.Properties)); | ||
|
||
foreach (var property in clrTypeInfo.Properties) | ||
{ | ||
codeFile.Properties.Add(new TypePropertyCodeConverter(property)); | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...erator/CodeGeneration/CodeConverters/CombinedCallbackParameterConstructorCodeConverter.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,36 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using WebExtensions.Net.Generator.Models.ClrTypes; | ||
|
||
namespace WebExtensions.Net.Generator.CodeGeneration.CodeConverters | ||
{ | ||
public class CombinedCallbackParameterConstructorCodeConverter : ICodeConverter | ||
{ | ||
private readonly string className; | ||
private readonly IEnumerable<ClrPropertyInfo> clrPropertyInfos; | ||
|
||
public CombinedCallbackParameterConstructorCodeConverter(string className, IEnumerable<ClrPropertyInfo> clrPropertyInfos) | ||
{ | ||
this.className = className; | ||
this.clrPropertyInfos = clrPropertyInfos; | ||
} | ||
|
||
public void WriteTo(CodeWriter codeWriter, CodeWriterOptions options) | ||
{ | ||
codeWriter.WriteUsingStatement("System"); | ||
|
||
var propertyTypes = clrPropertyInfos.Select(property => $"typeof({property.PropertyType.CSharpName})"); | ||
var propertyNames = clrPropertyInfos.Select(property => $"\"{property.PublicName}\""); | ||
|
||
codeWriter.Properties | ||
.WriteLine($"private static readonly Type[] propertyTypes = new[] {{ {string.Join(", ", propertyTypes)} }};") | ||
.WriteLine($"private static readonly string[] propertyNames = new[] {{ {string.Join(", ", propertyNames)} }};"); | ||
|
||
codeWriter.Constructors | ||
.WriteWithConverter(new CommentSummaryCodeConverter($"Creates a new instance of <see cref=\"{className}\" />.")) | ||
.WriteLine($"public {className}() : base(propertyTypes, propertyNames)") | ||
.WriteStartBlock() | ||
.WriteEndBlock(); | ||
} | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
...titiesRegistration/ClassEntityRegistrars/CombinedCallbackParameterClassEntityRegistrar.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,19 @@ | ||
using WebExtensions.Net.Generator.Models; | ||
using WebExtensions.Net.Generator.Repositories; | ||
|
||
namespace WebExtensions.Net.Generator.EntitiesRegistration.ClassEntityRegistrars | ||
{ | ||
public class CombinedCallbackParameterClassEntityRegistrar : BaseClassEntityRegistrar | ||
{ | ||
private readonly RegistrationOptions registrationOptions; | ||
|
||
public CombinedCallbackParameterClassEntityRegistrar(EntitiesContext entitiesContext, RegistrationOptions registrationOptions) : base(entitiesContext) | ||
{ | ||
this.registrationOptions = registrationOptions; | ||
} | ||
|
||
protected override ClassType GetClassType() => ClassType.CombinedCallbackParameterClass; | ||
protected override bool ShouldSortProperties() => false; | ||
protected override string? GetBaseClassName() => registrationOptions.CombinedCallbackParameterClassBaseClassName; | ||
} | ||
} |
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
Oops, something went wrong.