コード例 #1
0
        public void WriteClass(Type rType)
        {
            this.Write(0,
                       $"namespace {rType.Namespace}");
            this.Write(0,
                       "{");
            this.Write(1,
                       $"public partial class {rType.Name}");
            this.Write(1,
                       @"{
        public override void Serialize(BinaryWriter rWriter)
	    {
            base.Serialize(rWriter);");

            var rAllSerializeMembers = HotfixSerializerAssists.FindSerializeMembers(rType);

            for (int i = 0; i < rAllSerializeMembers.Count; i++)
            {
                var rMemberInfo = rAllSerializeMembers[i];
                var rParamText  = HotfixSerializerAssists.GetClassMemberDummyText(rAllSerializeMembers[i]);

                if (rMemberInfo.IsDefined(typeof(HotfixSBDynamicAttribute), true) &&
                    !HotfixSerializerAssists.IsBaseType(HotfixSerializerAssists.GetMemberType(rMemberInfo), false))
                {
                    this.Write(3, $"rWriter.SerializeDynamic({rParamText});");
                }
                else
                {
                    this.Write(3, $"rWriter.Serialize({rParamText});");
                }
            }
            this.Write(2,
                       "}");

            this.Write(2,
                       @"public override void Deserialize(BinaryReader rReader)
	    {
		    base.Deserialize(rReader);"        );

            for (int i = 0; i < rAllSerializeMembers.Count; i++)
            {
                var rMemberInfo      = rAllSerializeMembers[i];
                var rMemberText      = HotfixSerializerAssists.GetClassMemberTypeText(rMemberInfo);
                var rMemberDummyText = HotfixSerializerAssists.GetClassMemberDummyText(rMemberInfo);

                if (rMemberInfo.IsDefined(typeof(HotfixSBDynamicAttribute), false) &&
                    !HotfixSerializerAssists.IsBaseType(HotfixSerializerAssists.GetMemberType(rMemberInfo), false))
                {
                    this.Write(3, $"this.{rMemberInfo.Name} = {rMemberText}rReader.DeserializeDynamic({rMemberDummyText});");
                }
                else
                {
                    this.Write(3, $"this.{rMemberInfo.Name} = {rMemberText}rReader.Deserialize({rMemberDummyText});");
                }
            }
            this.Write(2,
                       @"}
    }
}
");
        }
コード例 #2
0
        public void WriteClass(Type rType)
        {
            this.StringBuilder?
            .F("namespace {0}", rType.Namespace).N()
            .A("{").N()
            .T(1).F("public partial class {0}", rType.Name).N()
            .T(1).A("{").N()
            .T(2).A("public override void Serialize(BinaryWriter rWriter)").N()
            .T(2).A("{").N()
            .T(3).A("base.Serialize(rWriter);").N();

            var rAllSerializeMembers = HotfixSerializerAssists.FindSerializeMembers(rType);

            for (int i = 0; i < rAllSerializeMembers.Count; i++)
            {
                var rMemberInfo = rAllSerializeMembers[i];
                var rParamText  = HotfixSerializerAssists.GetClassMemberDummyText(rAllSerializeMembers[i]);

                if (rMemberInfo.IsDefined(typeof(HotfixSBDynamicAttribute), true) &&
                    !HotfixSerializerAssists.IsBaseType(HotfixSerializerAssists.GetMemberType(rMemberInfo), false))
                {
                    this.StringBuilder?
                    .T(3).F("rWriter.SerializeDynamic({0});", rParamText).N();
                }
                else
                {
                    this.StringBuilder?
                    .T(3).F("rWriter.Serialize({0});", rParamText).N();
                }
            }
            this.StringBuilder
            .T(2).A("}").N();

            this.StringBuilder
            .T(2).A("public override void Deserialize(BinaryReader rReader)").N()
            .T(2).A("{").N()
            .T(3).A("base.Deserialize(rReader);").N();

            for (int i = 0; i < rAllSerializeMembers.Count; i++)
            {
                var rMemberInfo      = rAllSerializeMembers[i];
                var rMemberText      = HotfixSerializerAssists.GetClassMemberTypeText(rMemberInfo);
                var rMemberDummyText = HotfixSerializerAssists.GetClassMemberDummyText(rMemberInfo);

                if (rMemberInfo.IsDefined(typeof(HotfixSBDynamicAttribute), false) &&
                    !HotfixSerializerAssists.IsBaseType(HotfixSerializerAssists.GetMemberType(rMemberInfo), false))
                {
                    this.StringBuilder
                    .T(3).F("this.{0} = {1}rReader.DeserializeDynamic({2});", rMemberInfo.Name, rMemberText, rMemberDummyText).N();
                }
                else
                {
                    this.StringBuilder
                    .T(3).F("this.{0} = {1}rReader.Deserialize({2});", rMemberInfo.Name, rMemberText, rMemberDummyText).N();
                }
            }

            this.StringBuilder
            .T(2).A("}").N()
            .T(1).A("}").N()
            .A("}").N();
        }