-
Notifications
You must be signed in to change notification settings - Fork 806
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve AttributeTypeRef to handle type refs and other types of values
- Loading branch information
1 parent
f7c27ec
commit cc295d7
Showing
10 changed files
with
169 additions
and
114 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
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,13 +1,41 @@ | ||
namespace Serenity.CodeGenerator; | ||
namespace Serenity.CodeGenerator; | ||
|
||
public class AttributeTypeRef | ||
{ | ||
public string TypeName { get; set; } | ||
public string Arguments { get; set; } | ||
public string TypeName { get; } | ||
public object[] Arguments { get; } | ||
|
||
public AttributeTypeRef(string typeName, string arguments = null) | ||
public AttributeTypeRef(string typeName, params object[] arguments) | ||
{ | ||
TypeName = typeName; | ||
TypeName = typeName ?? throw new ArgumentNullException(nameof(typeName)); | ||
Arguments = arguments; | ||
} | ||
|
||
public string ToString(CodeWriter cw) | ||
{ | ||
var s = cw.ShortTypeRef(TypeName); | ||
if (Arguments == null || Arguments.Length == 0) | ||
return s; | ||
|
||
s += "("; | ||
for (var i = 0; i < Arguments.Length; i++) | ||
{ | ||
var value = Arguments[i]; | ||
if (i > 0) | ||
s += ", "; | ||
|
||
if (value is TypeNameRef tr) | ||
s += tr.ToString(cw); | ||
else if (value is string str) | ||
s += StringHelper.ToDoubleQuoted(str); | ||
else if (value is bool b) | ||
s += b ? "true" : "false"; | ||
else if (value is IFormattable fmt) | ||
s += fmt.ToString(null, CultureInfo.InvariantCulture); | ||
else | ||
s += value?.ToString() ?? "null"; | ||
} | ||
|
||
return s + ")"; | ||
} | ||
} |
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 @@ | ||
namespace Serenity.CodeGenerator; | ||
|
||
public class RawCode | ||
{ | ||
public string Code { get; } | ||
|
||
public RawCode(string code) | ||
{ | ||
Code = code ?? throw new ArgumentNullException(nameof(code)); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return Code; | ||
} | ||
} |
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 @@ | ||
namespace Serenity.CodeGenerator; | ||
|
||
public class TypeNameRef | ||
{ | ||
public string TypeName { get; } | ||
|
||
public TypeNameRef(string typeName) | ||
{ | ||
TypeName = typeName ?? throw new ArgumentNullException(nameof(typeName)); | ||
} | ||
|
||
public string ToString(CodeWriter cw) | ||
{ | ||
return "typeof(" + cw.ShortTypeRef(TypeName) + ")"; | ||
} | ||
} |
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.