Пример #1
0
        public override void Compile()
        {
            var cs = new List <DefBeanBase>();

            if (Children != null)
            {
                CollectHierarchyNotAbstractChildren(cs);
            }
            HierarchyNotAbstractChildren = cs;
            if (Id != 0)
            {
                throw new Exception($"bean:{FullName} beanid:{Id} should be 0!");
            }
            else
            {
                Id = TypeUtil.ComputCfgHashIdByName(FullName);
            }
            // 检查别名是否重复
            HashSet <string> nameOrAliasName = cs.Select(b => b.Name).ToHashSet();

            foreach (DefBean c in cs)
            {
                if (!string.IsNullOrWhiteSpace(c.Alias) && !nameOrAliasName.Add(c.Alias))
                {
                    throw new Exception($"bean:{FullName} alias:{c.Alias} 重复");
                }
            }
            DefField.CompileFields(this, HierarchyFields, false);
        }
Пример #2
0
        public static string GoDeserializeField(DefField field, string bufName)
        {
            var   name = field.CsStyleName;
            TType type = field.CType;

            if (field.CType.Apply(NeedMarshalBoolPrefixVisitor.Ins))
            {
                return($"{{ var _exists bool; if _exists, err = {bufName}.ReadBool(); err != nil {{ return }}; if _exists {{ if _v.{name}, err = {type.Apply(GoDeserializeVisitor.Ins, bufName)}; err != nil  {{ return }} }} }}");
            }
            else
            {
                return($"if _v.{name}, err = {type.Apply(GoDeserializeVisitor.Ins, bufName)}; err != nil  {{ return }} ");
            }
        }
Пример #3
0
 internal bool TryGetField(string index, out DefField field, out int fieldIndexId)
 {
     for (int i = 0; i < HierarchyFields.Count; i++)
     {
         if (HierarchyFields[i].Name == index)
         {
             field        = (DefField)HierarchyFields[i];
             fieldIndexId = i;
             return(true);
         }
     }
     field        = null;
     fieldIndexId = 0;
     return(false);
 }
Пример #4
0
        public static string JavaRefValidatorResolve(DefField field)
        {
            var refVarName = field.JavaRefVarName;
            var name       = field.JavaStyleName;
            var tableName  = field.Ref.FirstTable;
            var table      = field.Assembly.GetCfgTable(field.Ref.FirstTable);

            if (field.IsNullable)
            {
                return($"this.{refVarName} = this.{name} != null ? (({table.FullNameWithTopModule})_tables.get(\"{tableName}\")).get({name}) : null;");
            }
            else
            {
                return($"this.{refVarName} = (({table.FullNameWithTopModule})_tables.get(\"{tableName}\")).get({name});");
            }
        }
Пример #5
0
        public static string CsRefValidatorResolve(DefField field)
        {
            var refVarName = field.CsRefVarName;
            var name       = field.CsStyleName;
            var tableName  = field.Ref.FirstTable;
            var table      = field.Assembly.GetCfgTable(field.Ref.FirstTable);

            if (field.IsNullable)
            {
                return($"this.{refVarName} = this.{name} != null ? (_tables[\"{tableName}\"] as  {table.FullName}).GetOrDefault({name}.Value) : null;");
            }
            else
            {
                return($"this.{refVarName} = (_tables[\"{tableName}\"] as {table.FullName}).GetOrDefault({name});");
            }
        }
Пример #6
0
        public static string TsRefValidatorResolve(DefField field)
        {
            var refVarName = field.CsRefVarName;
            var name       = "this." + field.TsStyleName;
            var tableName  = field.Ref.FirstTable;
            var table      = field.Assembly.GetCfgTable(field.Ref.FirstTable);

            if (field.IsNullable)
            {
                return($"this.{refVarName} = {name} != null ? (_tables.get('{tableName}') as  {table.FullName}).get({name}) : null;");
            }
            else
            {
                return($"this.{refVarName} = (_tables.get('{tableName}') as {table.FullName}).get({name});");
            }
        }
Пример #7
0
        public override void Compile()
        {
            ResolveExternalType();

            var cs = new List <DefBeanBase>();

            if (Children != null)
            {
                CollectHierarchyNotAbstractChildren(cs);
            }
            HierarchyNotAbstractChildren = cs;
            if (Id != 0)
            {
                throw new Exception($"bean:'{FullName}' beanid:{Id} should be 0!");
            }
            else
            {
                Id = TypeUtil.ComputCfgHashIdByName(FullName);
            }
            // 检查别名是否重复
            HashSet <string> nameOrAliasName = cs.Select(b => b.Name).ToHashSet();

            foreach (DefBean c in cs)
            {
                if (!string.IsNullOrWhiteSpace(c.Alias) && !nameOrAliasName.Add(c.Alias))
                {
                    throw new Exception($"bean:'{FullName}' alias:{c.Alias} 重复");
                }
            }
            DefField.CompileFields(this, HierarchyFields, false);

            var allocAutoIds = this.HierarchyFields.Select(f => f.Id).ToHashSet();

            int nextAutoId = 1;

            foreach (var f in this.HierarchyFields)
            {
                while (!allocAutoIds.Add(nextAutoId))
                {
                    ++nextAutoId;
                }
                f.AutoId = nextAutoId;
            }
        }
Пример #8
0
 public static string JavaRecursiveResolve(DefField field, string tables)
 {
     return(field.CType.Apply(JavaRecursiveResolveVisitor.Ins, field.JavaStyleName, tables));
 }
Пример #9
0
 public static string TsRecursiveResolve(DefField field, string tables)
 {
     return(field.CType.Apply(TsRecursiveResolveVisitor.Ins, "this." + field.CsStyleName, tables));
 }