4 namespace CodeGen.generators
12 private const string ClassFormat =
"class {0} {1}\n{{{2}{3}{4}}}";
13 private string Indent {
get; } = GeneratorConf.GetIndent(UseTabs, 4);
19 if (
@class.Parent?.Length > 0)
21 parent =
" : " +
@class.Parent +
" " +
@class.Parent;
24 var
@public = GenerateSection(
"public",
@class);
25 var
@protected = GenerateSection(
"protected",
@class);
26 var
@private = GenerateSection(
"private",
@class);
27 return string.Format(ClassFormat,
@class.Name, parent,
@public,
@protected,
@private);
35 throw new ArgumentNullException();
49 result += field.Type +
" " + field.Name;
52 result +=
" = " + field.Default;
75 result += method.Type +
" ";
79 result += method.Name +
"(";
80 for (var i = 0; i < method.Parameters?.Length; i++)
82 var parameter = method.Parameters[i];
83 result += parameter.Type +
" " + parameter.Name;
84 if (!
string.IsNullOrWhiteSpace(parameter.Default))
86 result +=
" = " + parameter.Default;
104 private string GenerateSection(
string access,
Class @class)
106 var result =
@class.Fields?.Where(field => access == field.Access)
107 .Aggregate(
"", (current, field) => current + (GenerateField(field) +
"\n"));
109 result =
@class.Methods?.Where(method => access == method.Access).Aggregate(result,
110 (current, method) => current + (GeneratorConf.ShiftCode(GenerateMethod(method), 1, Indent) +
"\n"));
111 result =
@class.Classes?.Where(clas => access == clas.Access).Aggregate(result,
112 (current, clas) => current + (GeneratorConf.ShiftCode(GenerateClass(clas), 1, Indent) +
"\n"));
115 result =
"\n" + access +
":\n" + result;
bool Const
Denotes if field is constant or not. Type: boolean
string Type
Represents return type of the method. Type: string
The structure that describes class. Contains name, array of fields, methods and subclasses, parent class name, access specifier. Overrides ToString() method.
bool Static
Denotes if the mathod is static or not. Type: boolean
bool Static
Denotes if field is static or not. Type: boolean
Parameter[] Parameters
Represents parameters of the method. Type: array of type Parameter
override string GenerateClass(Class @class)
Class generator: generates class with fields, methods and subclasses from given class object Class ob...
override string GenerateField(Field field)
Field generator: generates field from given field object Field objectString of generated code of fiel...
string Default
Represents default value of the varibale. Type: string
Interface of language generator
override string GenerateMethod(Method method)
Method generator: generates method from given method object Method objectString of generated code of ...
The structure that describes method. Contains name, return type, access level, const and static prope...
The structure that describes field. Contains access, const and static properties. Inherits from Varia...