public string GetDeserializeUpdateIntoUpdateString(string updateFieldInstance, string schemaObject, uint fieldNumber, int indents) { var codeWriter = new CodeWriter(); using (codeWriter.Scope()) { codeWriter.WriteLine($"var mapSize = {schemaObject}.GetObjectCount({fieldNumber});"); CommonCodeWriterBlocks.WriteCheckIsCleared(codeWriter, fieldNumber); using (codeWriter.Scope("if (mapSize > 0 || isCleared)")) { codeWriter.WriteLine( $"{updateFieldInstance} = new global::Improbable.Gdk.Core.Option<{Type}>(new {Type}());"); } 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($"{updateFieldInstance}.Value.Add(key, value);"); } } return(CommonGeneratorUtils.IndentEveryNewline(codeWriter.Build(), indents)); }
public string GetDeserializeUpdateIntoUpdateString(string updateFieldInstance, string schemaObject, uint fieldNumber, int indents) { var codeWriter = new CodeWriter(); using (codeWriter.Scope()) { CommonCodeWriterBlocks.WriteCheckIsCleared(codeWriter, fieldNumber); using (codeWriter.Scope("if (isCleared)")) { codeWriter.WriteLine( $"{updateFieldInstance} = new global::Improbable.Gdk.Core.Option<{Type}>(new {Type}());"); } using (codeWriter.Scope($"else if ({containedType.GetCountExpression(schemaObject, fieldNumber)} == 1)") ) { codeWriter.WriteLine( $"{updateFieldInstance} = new global::Improbable.Gdk.Core.Option<{Type}>({containedType.GetDeserializationExpression(schemaObject, fieldNumber)});"); } } return(CommonGeneratorUtils.IndentEveryNewline(codeWriter.Build(), indents)); }
public string GetDeserializeUpdateIntoUpdateString(string updateFieldInstance, string schemaObject, uint fieldNumber, int indents) { var codeWriter = new CodeWriter(); using (codeWriter.Scope()) { codeWriter.WriteLine($"var listSize = {containedType.GetCountExpression(schemaObject, fieldNumber)};"); CommonCodeWriterBlocks.WriteCheckIsCleared(codeWriter, fieldNumber); using (codeWriter.Scope("if (listSize > 0 || isCleared)")) { codeWriter.WriteLine( $"{updateFieldInstance} = new global::Improbable.Gdk.Core.Option<{Type}>(new {Type}());"); } using (codeWriter.Scope("for (var i = 0; i < listSize; i++)")) { codeWriter.WriteLine( $"var value = {containedType.GetFieldIndexExpression(schemaObject, fieldNumber, "i")};"); codeWriter.WriteLine($"{updateFieldInstance}.Value.Add(value);"); } } return(CommonGeneratorUtils.IndentEveryNewline(codeWriter.Build(), indents)); }
public string GetDeserializeUpdateString(string fieldInstance, string schemaObject, uint fieldNumber, int indents) { var codeWriter = new CodeWriter(); using (codeWriter.Scope()) { CommonCodeWriterBlocks.WriteCheckIsCleared(codeWriter, fieldNumber); using (codeWriter.Scope("if (isCleared)")) { codeWriter.WriteLine($"{fieldInstance} = new {Type}();"); } using (codeWriter.Scope($"else if ({containedType.GetCountExpression(schemaObject, fieldNumber)} == 1)") ) { codeWriter.WriteLine( $"var value = {containedType.GetDeserializationExpression(schemaObject, fieldNumber)};"); codeWriter.WriteLine($"{fieldInstance} = new {Type}(value);"); } } return(CommonGeneratorUtils.IndentEveryNewline(codeWriter.Build(), indents)); }