-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0eea22d
commit 889b830
Showing
17 changed files
with
810 additions
and
570 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,82 @@ | ||
using Microsoft.CodeAnalysis; | ||
using System; | ||
using System.CodeDom.Compiler; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Generators.Shared.Builder | ||
namespace Generators.Shared.Builder; | ||
|
||
internal enum NodeType | ||
{ | ||
Unit, | ||
NameSpace, | ||
Class, | ||
Interface, | ||
Record, | ||
Constructor, | ||
Field, | ||
Property, | ||
Method, | ||
} | ||
internal enum MemberType | ||
{ | ||
internal enum NodeType | ||
Field, | ||
Property, | ||
Method, | ||
Constructor, | ||
} | ||
internal class ClassBuilder : MemberBuilder<ClassBuilder> | ||
{ | ||
public ClassBuilder() | ||
{ | ||
Unit, | ||
NameSpace, | ||
Class, | ||
Interface, | ||
Record, | ||
Constructor, | ||
Field, | ||
Property, | ||
Method, | ||
Modifiers = "public partial"; | ||
} | ||
internal enum MemberType | ||
public override NodeType Type => NodeType.Class; | ||
public override string Indent => " "; | ||
public string? BaseType { get; set; } | ||
public string ClassType { get; set; } = "class"; | ||
public IList<string> Interfaces { get; } = []; | ||
private string BaseTypeList | ||
{ | ||
Field, | ||
Property, | ||
Method, | ||
Constructor, | ||
get | ||
{ | ||
if (BaseType == null && !Interfaces.Any()) | ||
{ | ||
return ""; | ||
} | ||
string?[] all = [BaseType, .. Interfaces]; | ||
return $": {string.Join(", ", all.Where(b => !string.IsNullOrEmpty(b)))}"; | ||
} | ||
} | ||
internal class ClassBuilder : MemberBuilder<ClassBuilder> | ||
|
||
private IEnumerable<string> RenderMembers() | ||
{ | ||
public ClassBuilder() | ||
foreach (var m in Members.Where(m => m.Type == NodeType.Field)) | ||
{ | ||
Modifiers = "public partial"; | ||
yield return $"{m}"; | ||
} | ||
public override NodeType Type => NodeType.Class; | ||
public override string Indent => " "; | ||
public string? BaseType { get; set; } | ||
public IList<string> Interfaces { get; } = []; | ||
private string BaseTypeList | ||
foreach (var m in Members.Where(m => m.Type == NodeType.Constructor)) | ||
{ | ||
get | ||
{ | ||
if (BaseType == null && !Interfaces.Any()) | ||
{ | ||
return ""; | ||
} | ||
string?[] all = [BaseType, .. Interfaces]; | ||
return $": {string.Join(", ", all.Where(b => !string.IsNullOrEmpty(b)))}"; | ||
} | ||
yield return $"{m}"; | ||
} | ||
|
||
private IEnumerable<string> RenderMembers() | ||
foreach (var m in Members.Where(m => m.Type == NodeType.Property)) | ||
{ | ||
foreach (var m in Members.Where(m => m.Type == NodeType.Field)) | ||
{ | ||
yield return $"{m}"; | ||
} | ||
foreach (var m in Members.Where(m => m.Type == NodeType.Constructor)) | ||
{ | ||
yield return $"{m}"; | ||
} | ||
foreach (var m in Members.Where(m => m.Type == NodeType.Property)) | ||
{ | ||
yield return $"{m}"; | ||
} | ||
foreach (var m in Members.Where(m => m.Type == NodeType.Method)) | ||
{ | ||
yield return $"{m}"; | ||
} | ||
yield return $"{m}"; | ||
} | ||
|
||
public override string ToString() | ||
foreach (var m in Members.Where(m => m.Type == NodeType.Method)) | ||
{ | ||
return | ||
yield return $"{m}"; | ||
} | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return | ||
$$""" | ||
{{AttributeList}} | ||
{{Indent}}/// <inheritdoc/> | ||
{{Indent}}{{Modifiers}} class {{Name}} {{BaseTypeList}} | ||
{{Indent}}{{Modifiers}} {{ClassType}} {{Name}} {{BaseTypeList}} | ||
{{Indent}}{ | ||
{{string.Join("\n\n", RenderMembers())}} | ||
{{Indent}}} | ||
"""; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
namespace Generators.Shared.Builder | ||
| ||
namespace Generators.Shared.Builder; | ||
|
||
internal abstract class Node | ||
{ | ||
internal abstract class Node | ||
{ | ||
public abstract NodeType Type { get; } | ||
public virtual string Indent => ""; | ||
//public abstract new string ToString(); | ||
} | ||
public abstract NodeType Type { get; } | ||
public virtual string Indent => ""; | ||
//public abstract new string ToString(); | ||
} |
Oops, something went wrong.