예제 #1
0
        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>();
        }
예제 #2
0
        public FileGen(string fileName)
        {
            _fileName = fileName;
            _sb       = new StringBuilderWithIdent();

            _sb.AppendLineA(Constants.Imports);
        }
예제 #3
0
        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());
        }
예제 #4
0
        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());
        }
예제 #5
0
     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);
     }