Esempio n. 1
0
 public override string DoAccept(TType type, string jsonFieldName, string fieldName)
 {
     if (type.IsNullable)
     {
         return($"if({jsonFieldName} != null) {{ {type.Apply(TsUnderingDeserializeVisitor.Ins, jsonFieldName, fieldName)} }} else {{ {fieldName} = null; }}");
     }
     else
     {
         return(type.Apply(TsUnderingDeserializeVisitor.Ins, jsonFieldName, fieldName));
     }
 }
 public override string DoAccept(TType type, string jsonFieldName, string fieldName)
 {
     if (type.IsNullable)
     {
         return($"if({jsonFieldName} != undefined) {{ {type.Apply(TypescriptJsonUnderingConstructorVisitor.Ins, jsonFieldName, fieldName)} }} else {{ {fieldName} = undefined }}");
     }
     else
     {
         return(type.Apply(TypescriptJsonUnderingConstructorVisitor.Ins, jsonFieldName, fieldName));
     }
 }
Esempio n. 3
0
 public override string DoAccept(TType type, string jsonFieldName, string fieldName)
 {
     if (type.IsNullable)
     {
         return($"if {jsonFieldName} != None: {type.Apply(UnderringVisitor, jsonFieldName, fieldName)}");
     }
     else
     {
         return(type.Apply(UnderringVisitor, jsonFieldName, fieldName));
     }
 }
 public static string LuaSerializeWhileNil(string bufName, string fieldName, TType type)
 {
     if (type.IsNullable)
     {
         return($"if {fieldName} == nil then writeBool(false) elseif writeBool(true) {type.Apply(LuaUnderingSerializeVisitor.Ins, bufName, fieldName)} end");
     }
     else
     {
         return($"{type.Apply(LuaUnderingSerializeVisitor.Ins, bufName, type.Apply(LuaValueOrDefaultVisitor.Ins, fieldName))}");
     }
 }
Esempio n. 5
0
 public override string DoAccept(TType type, string bufName, string fieldName)
 {
     if (type.IsNullable)
     {
         return($"if({fieldName} != null){{ {bufName}.WriteBool(true); {type.Apply(CsUnderingSerializeVisitor.Ins, bufName, fieldName)} }} else {{ {bufName}.WriteBool(true); }}");
     }
     else
     {
         return(type.Apply(CsUnderingSerializeVisitor.Ins, bufName, fieldName));
     }
 }
 public override string DoAccept(TType type, string byteBufName, string fieldName)
 {
     if (type.IsNullable)
     {
         return($"if({byteBufName}.ReadBool()) {{ {type.Apply(TypescriptBinUnderingConstructorVisitor.Ins, byteBufName, fieldName)} }} else {{ {fieldName} = undefined }}");
     }
     else
     {
         return(type.Apply(TypescriptBinUnderingConstructorVisitor.Ins, byteBufName, fieldName));
     }
 }
 public static string DbTsCompatibleDeserialize(string bufName, string fieldName, TType type)
 {
     if (type.Apply(CompatibleSerializeNeedEmbedVisitor.Ins))
     {
         return $@"{{ let _state_ = {bufName}.EnterSegment(); {type.Apply(DbTypescriptCompatibleDeserializeVisitor.Ins, bufName, fieldName)} {bufName}.LeaveSegment(_state_); }}";
     }
     else
     {
         return type.Apply(DbTypescriptCompatibleDeserializeVisitor.Ins, bufName, fieldName);
     }
 }
Esempio n. 8
0
 public override string DoAccept(TType type, string bufName, string fieldName)
 {
     if (type.IsNullable)
     {
         return($"if({bufName}.ReadBool()){{ {type.Apply(CsUnderingDeserializeVisitor.Ins, bufName, fieldName)} }} else {{ {fieldName} = null; }}");
     }
     else
     {
         return(type.Apply(CsUnderingDeserializeVisitor.Ins, bufName, fieldName));
     }
 }
 public static string Py3DeserializeValue(string fieldName, string jsonVarName, TType type)
 {
     if (type.IsNullable)
     {
         return($"if {jsonVarName} != None: {type.Apply(PyUnderingDeserializeVisitor.Ins, jsonVarName, fieldName)}");
     }
     else
     {
         return(type.Apply(PyUnderingDeserializeVisitor.Ins, jsonVarName, fieldName));
     }
 }
 public static string Py3DeserializeField(string fieldName, string jsonVarName, string jsonFieldName, TType type)
 {
     if (type.IsNullable)
     {
         return($"if {jsonVarName}.get('{jsonFieldName}') != None: {type.Apply(PyUnderingDeserializeVisitor.Ins, $"{jsonVarName}['{jsonFieldName}']", fieldName)}");
     }
     else
     {
         return(type.Apply(PyUnderingDeserializeVisitor.Ins, $"{jsonVarName}['{jsonFieldName}']", fieldName));
     }
 }
 public static string DbTsCompatibleSerialize(string bufName, string fieldName, TType type)
 {
     if (type.Apply(CompatibleSerializeNeedEmbedVisitor.Ins))
     {
         return @$"{{let _state_ = {bufName}.BeginWriteSegment();{type.Apply(DbTypescriptCompatibleSerializeVisitor.Ins, bufName, fieldName)}; _buf.EndWriteSegment(_state_)}}";
     }
     else
     {
         return type.Apply(DbTypescriptCompatibleSerializeVisitor.Ins, bufName, fieldName);
     }
 }
 public static string DbCsCompatibleDeserialize(string bufName, string fieldName, TType type)
 {
     if (type.Apply(CompatibleSerializeNeedEmbedVisitor.Ins))
     {
         var sb = new StringBuilder($"{bufName}.EnterSegment(out var _state_);");
         sb.Append(type.Apply(DbCsCompatibleDeserializeVisitor.Ins, bufName, fieldName));
         sb.Append("_buf.LeaveSegment(_state_);");
         return sb.ToString();
     }
     else
     {
         return type.Apply(DbCsCompatibleDeserializeVisitor.Ins, bufName, fieldName);
     }
 }
Esempio n. 13
0
 private string GenList(TType elementType, string bufName)
 {
     return($@"func (_buf2 *serialization.ByteBuf) (_v2 []{elementType.Apply(GoTypeNameVisitor.Ins)}, err2 error) {{
         _v2 = make([]{elementType.Apply(GoTypeNameVisitor.Ins)}, 0)
         var n int
         if n, err2 = _buf2.ReadSize(); err2 != nil {{return}}
         for i := 0 ; i < n ; i++ {{
             var v3 {elementType.Apply(GoTypeNameVisitor.Ins)}
             if v3, err2 = {elementType.Apply(this, "_buf2")}; err2 != nil {{return}}
             _v2 = append(_v2, v3)
         }}
         return
         }}({bufName})");
 }
Esempio n. 14
0
        private string SaveList(TType elementType, string json, string field)
        {
            return($@"
            {{
                TArray<TSharedPtr<FJsonValue>> _arr;
                for (auto _v : this->{field})
                {{
                    {elementType.Apply(EditorUeCppTypeJsonValueTypeNameVisitor.Ins)}* _vj = nullptr;
                    {elementType.Apply(EditorUeCppSaveVisitor2.Ins, "_vj", "_v")}
                    _arr.Add(TSharedPtr<FJsonValue>(_vj));
                }}
                {json}->SetArrayField(""{field}"", _arr);
            }}
");
        }
Esempio n. 15
0
 public void Compile(DefFieldBase def)
 {
     foreach (var p in _valueSetStr.Split(',', ';'))
     {
         _datas.Add(_type.Apply(StringDataCreator.Ins, p));
     }
 }
Esempio n. 16
0
        // 容器类统统不支持 type.IsNullable
        // 因为貌似没意义?
        public List <DType> ReadList(TType type, object converter, ExcelStream stream, DefAssembly ass)
        {
            string sep   = type is TBean bean ? ((DefBean)bean.Bean).Sep : null;
            var    datas = new List <DType>();

            while (!stream.TryReadEOF())
            {
                if (string.IsNullOrWhiteSpace(sep))
                {
                    datas.Add(type.Apply(this, converter, stream, ass));
                }
                else
                {
                    datas.Add(type.Apply(this, converter, new ExcelStream(stream.ReadCell(), sep), ass));
                }
            }
            return(datas);
        }
Esempio n. 17
0
        public static string GetCollectionElementTypeSep(TType type)
        {
            if (type.Tags != null && type.Tags.TryGetValue("sep", out var s) && !string.IsNullOrWhiteSpace(s))
            {
                return(s);
            }

            return(type.Apply(IsNotSepTypeVisitor.Ins) ? SimpleContainerSep : "");
        }
Esempio n. 18
0
        private List <DType> ReadList(TType type, JsonElement e, DefAssembly ass)
        {
            var list = new List <DType>();

            foreach (var c in e.EnumerateArray())
            {
                list.Add(type.Apply(this, c, ass));
            }
            return(list);
        }
Esempio n. 19
0
        private List <DType> ReadList(TType type, XElement x, DefAssembly ass)
        {
            var list = new List <DType>();

            foreach (var e in x.Elements())
            {
                list.Add(type.Apply(this, e, ass));
            }
            return(list);
        }
 public override string DoAccept(TType type, string bufName, string fieldName)
 {
     if (type.IsNullable)
     {
         return($"{{ bool _has_value_; if(!{bufName}.readBool(_has_value_)){{return false;}}  if(_has_value_) {{ {fieldName}.reset({(type.IsBean ? "" : $"new {type.Apply(CppRawUnderingDefineTypeName.Ins)}()")}); {type.Apply(CppUnderingDeserializeVisitor.Ins, bufName, $"{(type.IsBean ? "" : "*")}{fieldName}")} }} else {{ {fieldName}.reset(); }} }}");
     }
     else
     {
         return(type.Apply(CppUnderingDeserializeVisitor.Ins, bufName, fieldName));
     }
 }
Esempio n. 21
0
 private string BeginSegment(TType type, string bufName)
 {
     if (type.Apply(CompatibleSerializeNeedEmbedVisitor.Ins))
     {
         return($"{bufName}.EnterSegment(out var _state2_);");
     }
     else
     {
         return("");
     }
 }
Esempio n. 22
0
 private string EndSegment(TType type, string bufName)
 {
     if (type.Apply(CompatibleSerializeNeedEmbedVisitor.Ins))
     {
         return($"{bufName}.LeaveSegment(_state2_);");
     }
     else
     {
         return("");
     }
 }
 public static string CsJsonDeserialize(string bufName, string fieldName, string jsonFieldName, TType type)
 {
     if (type.IsNullable)
     {
         return($"{{ if ({bufName}.TryGetProperty(\"{jsonFieldName}\", out var _j) && _j.ValueKind != JsonValueKind.Null) {{ {type.Apply(TypeVisitors.CsJsonDeserialize.Ins, "_j", fieldName)} }} else {{ {fieldName} = null; }} }}");
     }
     else
     {
         return(type.Apply(TypeVisitors.CsJsonDeserialize.Ins, $"{bufName}.GetProperty(\"{jsonFieldName}\")", fieldName));
     }
 }
        // 容器类统统不支持 type.IsNullable
        // 因为貌似没意义?
        public List <DType> ReadList(TType type, TType eleType, ExcelStream stream)
        {
            var datas = new List <DType>();

            stream = TrySep(type, stream);
            while (!stream.TryReadEOF())
            {
                datas.Add(eleType.Apply(this, stream));
            }
            return(datas);
        }
 public static string CsUnityJsonDeserialize(string bufName, string fieldName, string jsonFieldName, TType type)
 {
     if (type.IsNullable)
     {
         return($"{{ var _j = {bufName}[\"{jsonFieldName}\"]; if (_j.Tag != JSONNodeType.None && _j.Tag != JSONNodeType.NullValue) {{ {type.Apply(TypeVisitors.CsUnityJsonDeserialize.Ins, "_j", fieldName)} }} else {{ {fieldName} = null; }} }}");
     }
     else
     {
         return(type.Apply(TypeVisitors.CsUnityJsonDeserialize.Ins, $"{bufName}[\"{jsonFieldName}\"]", fieldName));
     }
 }
Esempio n. 26
0
 public override string DoAccept(TType type, string bufName, string fieldName)
 {
     if (type.IsNullable)
     {
         return($"{{ bool _read_succ_; if(!{bufName}.readBool(_read_succ_)){{return false;}}  if(_read_succ_) {{ {type.Apply(CppUnderingDeserializeVisitor.Ins, bufName, fieldName)} }} else {{ {fieldName} = {{}}; }} }}");
     }
     else
     {
         return(type.Apply(CppUnderingDeserializeVisitor.Ins, bufName, fieldName));
     }
 }
 public static string JavaJsonDeserialize(string jsonName, string fieldName, string jsonFieldName, TType type)
 {
     if (type.IsNullable)
     {
         return($"{{ if ({jsonName}.has(\"{jsonFieldName}\") && !{jsonName}.get(\"{jsonFieldName}\").isJsonNull()) {{ {type.Apply(TypeVisitors.JavaJsonDeserialize.Ins, $"{jsonName}.get(\"{jsonFieldName}\")", fieldName)} }} else {{ {fieldName} = null; }} }}");
     }
     else
     {
         return(type.Apply(TypeVisitors.JavaJsonDeserialize.Ins, $"{jsonName}.get(\"{jsonFieldName}\")", fieldName));
     }
 }
 public override string DoAccept(TType type, string fieldName, string bufName, string err)
 {
     if (type.IsNullable)
     {
         return($"{{ var __exists__ bool; if __exists__, {err} = {bufName}.ReadBool(); {err} != nil {{ return }}; if __exists__ {{ var __x__ {type.Apply(GoTypeUnderingNameVisitor.Ins)};  {type.Apply(GoDeserializeUnderingVisitor.Ins, "__x__", bufName, err)}; {fieldName} = {(type.Apply(GoIsPointerTypeVisitor.Ins) ? "&" : "")}__x__ }}}}");
     }
     else
     {
         return(type.Apply(GoDeserializeUnderingVisitor.Ins, fieldName, bufName, err));
     }
 }
Esempio n. 29
0
        private string LoadList(TType elementType, string json, string field)
        {
            return($@"
            {{
                const TArray<TSharedPtr<FJsonValue>>* _parr;
                if ({json}->TryGetArrayField(""{field}"", _parr))
                {{
                    for (const TSharedPtr<FJsonValue>& e : *_parr)
                    {{
                        {elementType.Apply(EditorUeCppDefineTypeVisitor.Ins)} _v;
                        {elementType.Apply(EditorUeCppLoadVisitor2.Ins, "e.Get()", "_v")}
                        this->{field}.Add(_v);
                    }}
                }}
                else
                {{
                    return false;
                }}
            }}
");
        }
Esempio n. 30
0
 public override string DoAccept(TType type, string varName, string fieldName, string bufName)
 {
     if (type.IsNullable)
     {
         var jsonObjName = $"__json_{fieldName}__";
         return($"{{ var _ok_ bool; var {jsonObjName} interface{{}}; if {jsonObjName}, _ok_ = {bufName}[\"{fieldName}\"]; !_ok_ || {jsonObjName} == nil {{ return }} else {{ var __x__ {type.Apply(GoTypeUnderingNameVisitor.Ins)};  {type.Apply(GoDeserializeJsonUndering2Visitor.Ins, "__x__", jsonObjName)}; {varName} = {(type.Apply(GoIsPointerTypeVisitor.Ins) ? "&" : "")}__x__ }}}}");
     }
     else
     {
         return(type.Apply(GoDeserializeJsonUnderingVisitor.Ins, varName, fieldName, bufName));
     }
 }