Пример #1
0
 public string GetDeserializationString(string fieldInstance, string schemaObject, uint fieldNumber)
 {
     return(new IfElseBlock($"{containedType.GetCountExpression(schemaObject, fieldNumber)} == 1", then =>
     {
         then.Line($"{fieldInstance} = new {Type}({containedType.GetDeserializationExpression(schemaObject, fieldNumber)});");
     }).Format());
 }
Пример #2
0
        public string GetDeserializationString(string fieldInstance, string schemaObject, uint fieldNumber, int indents)
        {
            var codeWriter = new CodeWriter();

            using (codeWriter.Scope($"if ({containedType.GetCountExpression(schemaObject, fieldNumber)} == 1)"))
            {
                codeWriter.WriteLine($"{fieldInstance} = new {Type}({containedType.GetDeserializationExpression(schemaObject, fieldNumber)});");
            }

            return(CommonGeneratorUtils.IndentEveryNewline(codeWriter.Build(), indents));
        }
Пример #3
0
        public string GetDeserializationString(string fieldInstance, string schemaObject, uint fieldNumber, int indents)
        {
            var codeWriter = new CodeWriter();

            using (codeWriter.Scope())
            {
                codeWriter.WriteLine($"var map = new {Type}();");
                codeWriter.WriteLine($"var mapSize = {schemaObject}.GetObjectCount({fieldNumber});");
                codeWriter.WriteLine($"{fieldInstance} = map;");
                using (codeWriter.Scope("for (var i = 0; i < mapSize; i++)"))
                {
                    codeWriter.WriteLine($"var mapObj = {schemaObject}.IndexObject({fieldNumber}, (uint) i);");
                    codeWriter.WriteLine($"var key = {keyType.GetDeserializationExpression("mapObj", 1)};");
                    codeWriter.WriteLine($"var value = {valueType.GetDeserializationExpression("mapObj", 2)};");
                    codeWriter.WriteLine("map.Add(key, value);");
                }
            }

            return(CommonGeneratorUtils.IndentEveryNewline(codeWriter.Build(), indents));
        }
Пример #4
0
        public string GetDeserializationString(string fieldInstance, string schemaObject, uint fieldNumber)
        {
            return(new CustomScopeBlock(scope =>
            {
                scope.Line(new[]
                {
                    $"var map = new {Type}();",
                    $"var mapSize = {schemaObject}.GetObjectCount({fieldNumber});",
                    $"{fieldInstance} = map;"
                });

                scope.Loop("for (var i = 0; i < mapSize; i++)", body =>
                {
                    body.Line(new[]
                    {
                        $"var mapObj = {schemaObject}.IndexObject({fieldNumber}, (uint) i);",
                        $"var key = {keyType.GetDeserializationExpression("mapObj", 1)};",
                        $"var value = {valueType.GetDeserializationExpression("mapObj", 2)};",
                        "map.Add(key, value);"
                    });
                });
            }).Format());
        }
Пример #5
0
 public string GetDeserializationString(string fieldInstance, string schemaObject, uint fieldNumber)
 {
     return($"{fieldInstance} = {containedType.GetDeserializationExpression(schemaObject, fieldNumber)};");
 }