コード例 #1
0
 // Find all reference types
 private static bool IsReferenceType(PropertyModel prop, ClassModel model)
 {
     return(!IsValueType(prop, model));
 }
コード例 #2
0
        //----------------------------------------
        // Generate loop for reading collections
        //----------------------------------------
        private void GenerateReadLoop(PropertyModel property, bool header)
        {
            if (!property.IsCollection)
            {
                return;
            }

            if (header)
            {
                // Read the length
                for (var dimension = 0; dimension < property.Dimensions; dimension++)
                {
        #line default
        #line hidden

        #line 337 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write("            var ");


        #line default
        #line hidden

        #line 338 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(FieldLength(property, dimension)));


        #line default
        #line hidden

        #line 338 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write(" = GeneratorByteConverter.ToUInt16(bytes, ref index);\r\n");


        #line default
        #line hidden

        #line 339 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                }
            }

            if (header && property.IsCollection)
            {
                // Create temp object


        #line default
        #line hidden

        #line 346 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write("            var temp");


        #line default
        #line hidden

        #line 347 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(property.Name));


        #line default
        #line hidden

        #line 347 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(" = ");


        #line default
        #line hidden

        #line 347 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(GeneratorTools.CollectionConstructor(property, FieldLength(property))));


        #line default
        #line hidden

        #line 347 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(";\r\n");


        #line default
        #line hidden

        #line 348 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"


                // Generate the loop
                var dimensions = new[] { "i", "j", "k" };
                for (var dimension = 0; dimension < property.Dimensions; dimension++)
                {
        #line default
        #line hidden

        #line 354 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write("            for (var ");


        #line default
        #line hidden

        #line 355 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(dimensions[dimension]));


        #line default
        #line hidden

        #line 355 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write(" = 0; ");


        #line default
        #line hidden

        #line 355 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(dimensions[dimension]));


        #line default
        #line hidden

        #line 355 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write(" < ");


        #line default
        #line hidden

        #line 355 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(FieldLength(property, dimension)));


        #line default
        #line hidden

        #line 355 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write("; ");


        #line default
        #line hidden

        #line 355 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(dimensions[dimension]));


        #line default
        #line hidden

        #line 355 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write("++)\r\n");


        #line default
        #line hidden

        #line 356 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                }


        #line default
        #line hidden

        #line 358 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write("            {\r\n");


        #line default
        #line hidden

        #line 360 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            }
            else if (!header && property.IsCollection)
            {
                var collAssignment = property.CollectionType == "Array"
                ? $"temp{property.Name}[{FieldPosition(property)}] = value"
                : $"temp{property.Name}.Add(value)";



        #line default
        #line hidden

        #line 368 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write("                ");


        #line default
        #line hidden

        #line 369 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(collAssignment));


        #line default
        #line hidden

        #line 369 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(";\r\n            }\r\n            ");


        #line default
        #line hidden

        #line 371 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(property.Name));


        #line default
        #line hidden

        #line 371 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(" = temp");


        #line default
        #line hidden

        #line 371 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(property.Name));


        #line default
        #line hidden

        #line 371 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(";\r\n");


        #line default
        #line hidden

        #line 372 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            }
        }
コード例 #3
0
        private bool CollectionWrapper(PropertyModel prop, bool head)
        {
            if (!prop.IsCollection)
            {
                return(false);
            }

            if (head)
            {
        #line default
        #line hidden

        #line 93 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                this.Write(" \r\n                if (");


        #line default
        #line hidden

        #line 94 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(prop.Name));


        #line default
        #line hidden

        #line 94 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                this.Write(" != null)\r\n                {\r\n                    var temp");


        #line default
        #line hidden

        #line 96 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(prop.Name));


        #line default
        #line hidden

        #line 96 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                this.Write(" = ");


        #line default
        #line hidden

        #line 96 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(GeneratorTools.CollectionConstructor(prop, $"{prop.Name}.{GeneratorTools.CollectionSize(prop)}")));


        #line default
        #line hidden

        #line 96 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                this.Write(";\r\n");


        #line default
        #line hidden

        #line 97 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"

                if (GeneratorTools.SupportsForLoop(prop))
                {
        #line default
        #line hidden

        #line 100 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write("                    for (var i = 0; i < ");


        #line default
        #line hidden

        #line 101 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(prop.Name));


        #line default
        #line hidden

        #line 101 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write(".");


        #line default
        #line hidden

        #line 101 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(GeneratorTools.CollectionSize(prop)));


        #line default
        #line hidden

        #line 101 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write("; i++)\r\n                    {\r\n                        var value = ");


        #line default
        #line hidden

        #line 103 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(prop.Name));


        #line default
        #line hidden

        #line 103 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write("[i];\r\n");


        #line default
        #line hidden

        #line 104 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                }
                else
                {
        #line default
        #line hidden

        #line 108 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write("                    foreach (var value in ");


        #line default
        #line hidden

        #line 109 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(prop.Name));


        #line default
        #line hidden

        #line 109 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write(")\r\n                    {\r\n");


        #line default
        #line hidden

        #line 111 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                }
            }
            else
            {
                if (prop.CollectionType == "Array")
                {
        #line default
        #line hidden

        #line 118 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write("                        temp");


        #line default
        #line hidden

        #line 119 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(prop.Name));


        #line default
        #line hidden

        #line 119 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write("[i] = value;\r\n");


        #line default
        #line hidden

        #line 120 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                }
                else
                {
        #line default
        #line hidden

        #line 124 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write("                        temp");


        #line default
        #line hidden

        #line 125 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(prop.Name));


        #line default
        #line hidden

        #line 125 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                    this.Write(".Add(value);\r\n");


        #line default
        #line hidden

        #line 126 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                }


        #line default
        #line hidden

        #line 128 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                this.Write("                    }\r\n                    copy.");


        #line default
        #line hidden

        #line 130 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(prop.Name));


        #line default
        #line hidden

        #line 130 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                this.Write(" = temp");


        #line default
        #line hidden

        #line 130 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(prop.Name));


        #line default
        #line hidden

        #line 130 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
                this.Write(";\r\n                }\r\n");


        #line default
        #line hidden

        #line 132 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Clone\CloneGenerator.tt"
            }

            return(true);
        }
コード例 #4
0
        //--------------------------------------
        // Code fragments wrapping a collection
        //--------------------------------------
        private void CollectionWrapper(PropertyModel property, bool start)
        {
            if (!property.IsCollection || property.ValueType == ModelValueType.Byte)
            {
                return;
            }

            if (start)
            {
        #line default
        #line hidden

        #line 244 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write("            if (");


        #line default
        #line hidden

        #line 245 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(property.Name));


        #line default
        #line hidden

        #line 245 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(" != null)\r\n            {\r\n");


        #line default
        #line hidden

        #line 247 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"

                if (GeneratorTools.SupportsForLoop(property))
                {
                    var dimensions = new[] { "i", "j", "k" };
                    for (var dimension = 0; dimension < property.Dimensions; dimension++)
                    {
                        var targetDimension = property.Dimensions > 1 ? dimension : -1;



        #line default
        #line hidden

        #line 255 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                        this.Write("                for(var ");


        #line default
        #line hidden

        #line 256 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(dimensions[dimension]));


        #line default
        #line hidden

        #line 256 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                        this.Write(" = 0; ");


        #line default
        #line hidden

        #line 256 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(dimensions[dimension]));


        #line default
        #line hidden

        #line 256 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                        this.Write(" < ");


        #line default
        #line hidden

        #line 256 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(property.Name));


        #line default
        #line hidden

        #line 256 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                        this.Write(".");


        #line default
        #line hidden

        #line 256 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(GeneratorTools.CollectionSize(property, targetDimension)));


        #line default
        #line hidden

        #line 256 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                        this.Write("; ");


        #line default
        #line hidden

        #line 256 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                        this.Write(this.ToStringHelper.ToStringWithCulture(dimensions[dimension]));


        #line default
        #line hidden

        #line 256 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                        this.Write("++)\r\n");


        #line default
        #line hidden

        #line 257 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    }


        #line default
        #line hidden

        #line 259 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write("                {\r\n                    var value = ");


        #line default
        #line hidden

        #line 261 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(property.Name));


        #line default
        #line hidden

        #line 261 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write("[");


        #line default
        #line hidden

        #line 261 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(string.Join(",", Enumerable.Range(0, property.Dimensions).Select(i => dimensions[i]))));


        #line default
        #line hidden

        #line 261 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write("];\r\n");


        #line default
        #line hidden

        #line 262 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                }
                else
                {
        #line default
        #line hidden

        #line 266 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write("                foreach(var value in ");


        #line default
        #line hidden

        #line 267 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(property.Name));


        #line default
        #line hidden

        #line 267 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                    this.Write(")\r\n                {\r\n");


        #line default
        #line hidden

        #line 269 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                }
            }
            else
            {
        #line default
        #line hidden

        #line 275 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write("                }\r\n            }\r\n");


        #line default
        #line hidden

        #line 278 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            }
        }
コード例 #5
0
        //--------------------------------------
        // Read property from the byte stream
        //--------------------------------------
        private void FromBytes(PropertyModel property)
        {
            var target = property.IsCollection ? "var value" : property.Name;
            var indent = property.IsCollection ? "\t" : string.Empty;

            var    increment = string.Empty;
            string conversion;

            switch (property.ValueType)
            {
            case ModelValueType.Class:
                conversion = Tools.ClassFromBytes(Model, property);
                break;

            case ModelValueType.Byte:
                conversion = "bytes[index++]";
                break;

            case ModelValueType.String:
                conversion = $"GeneratorByteConverter.GetString(bytes, ref index)";
                break;

            default:
                conversion = $"GeneratorByteConverter.To{property.ValueType.ToString("G")}(bytes, ref index)";
                break;
            }

            GenerateReadLoop(property, true);



        #line default
        #line hidden

        #line 310 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            this.Write("            ");


        #line default
        #line hidden

        #line 311 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(indent));


        #line default
        #line hidden

        #line 311 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(target));


        #line default
        #line hidden

        #line 311 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            this.Write(" = ");


        #line default
        #line hidden

        #line 311 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(conversion));


        #line default
        #line hidden

        #line 311 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            this.Write(";\r\n");


        #line default
        #line hidden

        #line 312 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"

            if (!string.IsNullOrEmpty(increment))
            {
        #line default
        #line hidden

        #line 315 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write("            ");


        #line default
        #line hidden

        #line 316 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(indent));


        #line default
        #line hidden

        #line 316 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write("index += ");


        #line default
        #line hidden

        #line 316 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(increment));


        #line default
        #line hidden

        #line 316 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(";\r\n");


        #line default
        #line hidden

        #line 317 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            }

            GenerateReadLoop(property, false);
        }
コード例 #6
0
        //---------------------------------------------
        // Generate a byte conversion for this field
        //--------------------------------------------
        private void ToBytes(PropertyModel property)
        {
            // Indentation throughout the method
            var indent = property.IsCollection && property.ValueType != ModelValueType.Byte ? "\t" : string.Empty;

            // Optional length prefix
            GenerateLengthPrefix(property);

            CollectionWrapper(property, true);

            // Now we add the real value
            var    target = property.IsCollection ? "value" : property.Name;
            var    nullable = false;
            string conversion, increment = null;

            switch (property.ValueType)
            {
            case ModelValueType.String:
                conversion = $"GeneratorByteConverter.Include({target}, bytes, ref index)";
                break;

            case ModelValueType.Class:
                conversion = Tools.ClassToBytes(Model, property);
                break;

            case ModelValueType.Boolean:
                conversion = $"bytes[index++] = {target} ? (byte)1 : (byte)0";
                break;

            case ModelValueType.Byte:
                conversion = property.IsCollection ? BlockCopy(false, property.Name, $"{property.Name}.Length") : $"bytes[index++] = {target}";
                increment  = property.IsCollection ? $"{property.Name}.Length" : null;
                nullable   = property.IsCollection;
                break;

            default:
                conversion = BlockCopy(true, target, BinarySize.OfProperty(property).ToString("D"));
                break;
            }

            if (nullable || property.IsCollection)
            {
                indent += "\t";
            }

            NullableWrapper(property, nullable, true);



        #line default
        #line hidden

        #line 167 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            this.Write("            ");


        #line default
        #line hidden

        #line 168 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(indent));


        #line default
        #line hidden

        #line 168 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(conversion));


        #line default
        #line hidden

        #line 168 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            this.Write(";\r\n");


        #line default
        #line hidden

        #line 169 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"

            if (!string.IsNullOrEmpty(increment))
            {
        #line default
        #line hidden

        #line 172 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write("            ");


        #line default
        #line hidden

        #line 173 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(indent));


        #line default
        #line hidden

        #line 173 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write("index += ");


        #line default
        #line hidden

        #line 173 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(increment));


        #line default
        #line hidden

        #line 173 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
                this.Write(";\r\n");


        #line default
        #line hidden

        #line 174 "C:\Users\Thomas\Documents\Development\CGbR\CGbR\Generator\Serialization\BinarySerializerGenerator.tt"
            }

            NullableWrapper(property, nullable, false);

            CollectionWrapper(property, false);
        }
コード例 #7
0
        //---------------------------
        // Generate length variable
        //---------------------------
        private static string FieldPosition(PropertyModel property)
        {
            var dimensions = new[] { "i", "j", "k" };

            return(string.Join(",", Enumerable.Range(0, property.Dimensions).Select(i => dimensions[i])));
        }
コード例 #8
0
 //---------------------------
 // Generate length variable
 //---------------------------
 private static string FieldLength(PropertyModel property)
 {
     return(string.Join(",", Enumerable.Range(0, property.Dimensions).Select(i => FieldLength(property, i))));
 }
コード例 #9
0
ファイル: BinarySize.cs プロジェクト: heathi/CGbR
 /// <summary>
 /// Get the binary size of a property
 /// </summary>
 /// <param name="model">Property model</param>
 /// <returns>Size of the propety in bytes</returns>
 public static int OfProperty(PropertyModel model)
 {
     return(OfType(model.ValueType));
 }
コード例 #10
0
 private static CodeElementModel GetChild(ClassModel model, PropertyModel property)
 {
     return(model.References.FirstOrDefault(r => r.Name == property.ElementType));
 }