public TypeGen(StringBuilderWithIdent sb) { _sb = sb; _sb.AppendLineA($"public class {Constants.ClassName} : LuaObject"); _sb.AppendLineA("{"); _sb.Ident++; _sb.AppendLineNoIdentA(Constants.Fields); _sb.AppendLineNoIdentA(Constants.FieldsInit); _sb.AppendLineNoIdentA(Constants.ImplicitCtor); _fields = new HashSet <string>(); _fieldsInit = new Dictionary <string, Operand>(); }
public FileGen(string fileName) { _fileName = fileName; _sb = new StringBuilderWithIdent(); _sb.AppendLineA(Constants.Imports); }
private string GetFieldsListInit() { StringBuilderWithIdent sb = new StringBuilderWithIdent { Ident = 1 }; foreach (var field in _fieldsInit) { sb.AppendLineA($"public dynamic {field.Key} = {field.Value};"); } return(sb.ToString()); }
private string GetDependencyInit() { var sb = new StringBuilderWithIdent() { Ident = 2 }; foreach (var dependencyInitializer in Env.Instance.GetDependencyInitializers()) { sb.AppendLineA($"this.{dependencyInitializer.Key} = new {dependencyInitializer.Value}();"); } return(sb.ToString()); }
public void End(string className) { _sb.Ident--; _sb.AppendLineA("}"); _sb.Replace(Constants.ClassName, className); _sb.Replace(Constants.Fields, GetFieldsList()); _fieldsInit.Remove(className); if (!Env.Instance.hasBeenCtor) { _sb.Replace(Constants.ImplicitCtor, $@" public {className}() {{ {Constants.Dependencies} {Constants.InitCode} }}"); } else { _sb.Replace(Constants.ImplicitCtor, string.Empty); } _sb.Replace(Constants.FieldsInit, GetFieldsListInit()); _sb.Replace(Constants.Dependencies, GetDependencyInit()); _sb.ReplaceB(Constants.InitCode); }