Exemple #1
0
        public string GetSerializationStatement(string instance, string schemaObject, uint fieldNumber)
        {
            switch (Category)
            {
            case ValueType.Primitive:
                return($"{schemaObject}.{SchemaFunctionMappings.AddSchemaFunctionFromType(PrimitiveType.Value)}({fieldNumber}, {instance});");

            case ValueType.Enum:
                var shifter = UnityEnumDetails.GetEnumMinimum(FqnType);
                return($"{schemaObject}.AddEnum({fieldNumber}, (uint) ({instance}) + {shifter});");

            case ValueType.Type:
                return($"{FqnType}.Serialization.Serialize({instance}, {schemaObject}.AddObject({fieldNumber}));");

            default:
                throw new ArgumentOutOfRangeException(nameof(Category), "Unknown type category encountered.");
            }
        }
Exemple #2
0
        public string GetDeserializationExpression(string schemaObject, uint fieldNumber)
        {
            switch (Category)
            {
            case ValueType.Primitive:
                return
                    ($"{schemaObject}.{SchemaFunctionMappings.GetSchemaFunctionFromType(PrimitiveType.Value)}({fieldNumber})");

            case ValueType.Enum:
                var shifter = UnityEnumDetails.GetEnumMinimum(FqnType);
                return($"({FqnType}) ({schemaObject}.GetEnum({fieldNumber}) - {shifter})");

            case ValueType.Type:
                return($"{FqnType}.Serialization.Deserialize({schemaObject}.GetObject({fieldNumber}))");

            default:
                throw new ArgumentOutOfRangeException(nameof(Category), "Unknown type category encountered.");
            }
        }