コード例 #1
0
        public void WriteDictionary(Type rType, bool bDynamic)
        {
            if (this.ReceiveGeneratedDictionaryType(rType, bDynamic))
            {
                return;
            }

            var rTypeName  = HotfixSerializerAssists.GetTypeName(rType);
            var rKeyType   = rType.GetGenericArguments()[0];
            var rValueType = rType.GetGenericArguments()[1];

            var rTDText  = bDynamic ? "Dynamic" : string.Empty;
            var rTDKText = bDynamic && !HotfixSerializerAssists.IsBaseType(rKeyType, false) ? "Dynamic" : string.Empty;
            var rTDVText = bDynamic && !HotfixSerializerAssists.IsBaseType(rValueType, false) ? "Dynamic" : string.Empty;

            this.StringBuilder?
            .T(2).F("public static void Serialize{0}(this BinaryWriter rWriter, {1} value)", rTDText, rTypeName).N()
            .T(2).A("{").N()
            .T(3).A("var bValid = (null != value);").N()
            .T(3).A("rWriter.Serialize(bValid);").N()
            .T(3).A("if (!bValid) return;").N()
            .L(1)
            .T(3).A("rWriter.Serialize(value.Count);").N()
            .T(3).A("foreach(var rPair in value)").N()
            .T(3).A("{").N()
            .T(4).F("rWriter.Serialize{0}({1});", rTDKText, (rKeyType.IsEnum ? "(int)rPair.Key" : "rPair.Key")).N()
            .T(4).F("rWriter.Serialize{0}({1});", rTDVText, (rValueType.IsEnum ? "(int)rPair.Value" : "rPair.Value")).N()
            .T(3).A("}").N()
            .T(2).A("}").N()
            .L(1);

            this.StringBuilder?
            .T(2).F("public static {0} Deserialize{1}(this BinaryReader rReader, {2} value)", rTypeName, rTDText, rTypeName).N()
            .T(2).A("{").N()
            .T(3).A("var bValid = rReader.Deserialize(default(bool));").N()
            .T(3).A("if (!bValid) return null;").N()
            .L(1)
            .T(3).A("var nCount  = rReader.Deserialize(default(int));").N()
            .T(3).F("var rResult = new {0}();", rTypeName).N()
            .T(3).A("for (int nIndex = 0; nIndex < nCount; ++ nIndex)").N()
            .T(3).A("{").N()
            .T(4).F("var rKey   = {0}rReader.Deserialize{1}({2});",
                    (rKeyType.IsEnum ? string.Format("({0})", rKeyType.FullName) : string.Empty),
                    rTDKText,
                    HotfixSerializerAssists.GetDeserializeUnwrap(rKeyType)).N()
            .T(4).F("var rValue = {0}rReader.Deserialize{1}({2});",
                    (rValueType.IsEnum ? string.Format("({0})", rValueType.FullName) : string.Empty),
                    rTDVText,
                    HotfixSerializerAssists.GetDeserializeUnwrap(rValueType)).N()
            .T(4).A("rResult.Add(rKey, rValue);").N()
            .T(3).A("}").N()
            .T(3).A("return rResult;").N()
            .T(2).A("}").N()
            .L(1);
        }
コード例 #2
0
        public void WriteDictionary(Type rType, bool bDynamic)
        {
            if (this.ReceiveGeneratedDictionaryType(rType, bDynamic))
            {
                return;
            }

            var rTypeName  = HotfixSerializerAssists.GetTypeName(rType);
            var rKeyType   = rType.GetGenericArguments()[0];
            var rValueType = rType.GetGenericArguments()[1];

            var rTDText  = bDynamic ? "Dynamic" : string.Empty;
            var rTDKText = bDynamic && !HotfixSerializerAssists.IsBaseType(rKeyType, false) ? "Dynamic" : string.Empty;
            var rTDVText = bDynamic && !HotfixSerializerAssists.IsBaseType(rValueType, false) ? "Dynamic" : string.Empty;

            this.WriteBraceCode(2,
                                $"public static void Serialize{rTDText}(this BinaryWriter rWriter, {rTypeName} value)",
                                @"{",
                                $@"var bValid = (null != value);
			rWriter.Serialize(bValid);
			if (!bValid) return;

			rWriter.Serialize(value.Count);
            {this.GenerateBraceCode(0, 
            "foreach(var rPair in value)",
"            {",
$@"            rWriter.Serialize{rTDKText}({(rKeyType.IsEnum ? "(int)rPair.Key" : "rPair.Key")});
				rWriter.Serialize{rTDVText}({(rValueType.IsEnum ? "(int)rPair.Value" : "rPair.Value")});",
"            }")}",
                                "}");

            this.WriteBraceCode(2,
                                $"public static {rTypeName} Deserialize{rTDText}(this BinaryReader rReader, {rTypeName} value)",
                                @"{",
                                $@"var bValid = rReader.Deserialize(default(bool));
			if (!bValid) return null;

			var nCount  = rReader.Deserialize(default(int));
            var rResult = new {rTypeName}();
            {this.GenerateBraceCode(0,
            "for (int nIndex = 0; nIndex < nCount; ++ nIndex)",
"            {",
$@"            var rKey   = {(rKeyType.IsEnum ? string.Format("({0})", rKeyType.FullName) : string.Empty)}rReader.Deserialize{rTDKText}({HotfixSerializerAssists.GetDeserializeUnwrap(rKeyType)});
                var rValue = {(rValueType.IsEnum ? string.Format("({0})", rValueType.FullName) : string.Empty)}rReader.Deserialize{rTDVText}({HotfixSerializerAssists.GetDeserializeUnwrap(rValueType)});
                rResult.Add(rKey, rValue);",
"            }")}
            return rResult;",
                                "}");
        }
コード例 #3
0
        public void WriteArray(Type rType, bool bDynamic)
        {
            if (this.ReceiveGeneratedArrayType(rType, bDynamic))
            {
                return;
            }

            var rTypeName    = HotfixSerializerAssists.GetTypeName(rType);
            var rElementType = rType.GetElementType();

            var rTDText  = bDynamic ? "Dynamic" : string.Empty;
            var rTDEText = bDynamic && !HotfixSerializerAssists.IsBaseType(rElementType, false) ? "Dynamic" : string.Empty;

            this.StringBuilder?
            .T(2).F("public static void Serialize{0}(this BinaryWriter rWriter, {1} value)", rTDText, rTypeName).N()
            .T(2).A("{").N()
            .T(3).A("var bValid = (null != value);").N()
            .T(3).A("rWriter.Serialize(bValid);").N()
            .T(3).A("if (!bValid) return;").N()
            .L(1)
            .T(3).A("rWriter.Serialize(value.Length);").N()
            .T(3).A("for (int nIndex = 0; nIndex < value.Length; nIndex++)").N()
            .T(4).F("rWriter.Serialize{0}({1});", rTDEText, (rElementType.IsEnum ? "(int)value[nIndex]" : "value[nIndex]")).N()
            .T(2).A("}").N()
            .L(1);

            this.StringBuilder?
            .T(2).F("public static {0} Deserialize(this BinaryReader rReader, {1} value)", rTypeName, rTypeName).N()
            .T(2).A("{").N()
            .T(3).A("var bValid = rReader.Deserialize(default(bool));").N()
            .T(3).A("if (!bValid) return null;").N()
            .L(1)
            .T(3).A("var nCount  = rReader.Deserialize(default(int));").N()
            .T(3).F("var rResult = new {0};", rTypeName.Insert(rTypeName.IndexOf('[') + 1, "nCount")).N()
            .T(3).A("for (int nIndex = 0; nIndex < nCount; nIndex++)").N()
            .T(4).F("rResult[nIndex] = {0}rReader.Deserialize{1}({2});",
                    (rElementType.IsEnum ? string.Format("({0})", rElementType.FullName) : string.Empty),
                    rTDEText,
                    HotfixSerializerAssists.GetDeserializeUnwrap(rElementType)).N()
            .T(3).A("return rResult;").N()
            .T(2).A("}").N()
            .L(1);
        }
コード例 #4
0
        public void WriteArray(Type rType, bool bDynamic)
        {
            if (this.ReceiveGeneratedArrayType(rType, bDynamic))
            {
                return;
            }

            var rTypeName    = HotfixSerializerAssists.GetTypeName(rType);
            var rElementType = rType.GetElementType();

            var rTDText  = bDynamic ? "Dynamic" : string.Empty;
            var rTDEText = bDynamic && !HotfixSerializerAssists.IsBaseType(rElementType, false) ? "Dynamic" : string.Empty;

            this.WriteBraceCode(2,
                                $"public static void Serialize{rTDText}(this BinaryWriter rWriter, {rTypeName} value)",
                                "{",
                                $@"var bValid = (null != value);
	        rWriter.Serialize(bValid);
	        if (!bValid) return;

	        rWriter.Serialize(value.Length); 
	        for (int nIndex = 0; nIndex < value.Length; nIndex++)
                rWriter.Serialize{rTDEText}({(rElementType.IsEnum ? "(int)value[nIndex]" : "value[nIndex]")});",
                                "}");

            this.WriteBraceCode(2,
                                $"public static {rTypeName} Deserialize(this BinaryReader rReader, {rTypeName} value)",
                                "{",
                                $@"var bValid = rReader.Deserialize(default(bool));
			if (!bValid) return null;

            var nCount  = rReader.Deserialize(default(int));
            var rResult = new {rTypeName.Insert(rTypeName.IndexOf('[') + 1, "nCount")};
			for (int nIndex = 0; nIndex < nCount; nIndex++)
                rResult[nIndex] = {(rElementType.IsEnum ? string.Format("({0})", rElementType.FullName) : string.Empty)}rReader.Deserialize{rTDEText}({HotfixSerializerAssists.GetDeserializeUnwrap(rElementType)});
            return rResult;",
                                "}");
        }