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:
                return($"{schemaObject}.AddEnum({fieldNumber}, (uint) {instance});");

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

            default:
                throw new ArgumentOutOfRangeException(nameof(category), "Unknown type category encountered.");
            }
        }
        public string GetFieldIndexExpression(string schemaObject, uint fieldNumber, string index)
        {
            switch (category)
            {
            case ValueType.Primitive:
                return
                    ($"{schemaObject}.{SchemaFunctionMappings.IndexSchemaFunctionFromType(primitiveType.Value)}({fieldNumber}, (uint) {index})");

            case ValueType.Enum:
                return($"({FqnType}) {schemaObject}.IndexEnum({fieldNumber}, (uint) {index})");

            case ValueType.Type:
                return($"{FqnType}.Serialization.Deserialize({schemaObject}.IndexObject({fieldNumber}, (uint) {index}))");

            default:
                throw new ArgumentOutOfRangeException(nameof(category), "Unknown type category encountered.");
            }
        }
        public string GetCountExpression(string schemaObject, uint fieldNumber)
        {
            switch (category)
            {
            case ValueType.Primitive:
                return
                    ($"{schemaObject}.{SchemaFunctionMappings.GetCountSchemaFunctionFromType(primitiveType.Value)}({fieldNumber})");

            case ValueType.Enum:
                return($"{schemaObject}.GetEnumCount({fieldNumber})");

            case ValueType.Type:
                return($"{schemaObject}.GetObjectCount({fieldNumber})");

            default:
                throw new ArgumentOutOfRangeException(nameof(category), "Unknown type category encountered.");
            }
        }
示例#4
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.");
            }
        }