Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine(@"http://www.AutoCSer.com/Serialize/Binary.html
");
            Console.WriteLine(Reference.TestCase());
            Console.WriteLine(DisabledReference.TestCase());
            Console.WriteLine(PublicInstanceField.TestCase());
            Console.WriteLine(Property.TestCase());
            Console.WriteLine(IgnoreMember.TestCase());
            Console.WriteLine(Json.TestCase());
            Console.WriteLine(MemberMap.TestCase());
            Console.WriteLine(DisabledMemberMap.TestCase());
            Console.WriteLine(MemberMapValue.TestCase());
            Console.WriteLine(BaseType.TestCase());
            Console.WriteLine(CustomClass.TestCase());
            Console.WriteLine(CustomStruct.TestCase());
            Console.WriteLine("Over");
            Console.ReadKey();
        }
        internal static bool TestCase()
        {
            DisabledMemberMap value = new DisabledMemberMap {
                Value1 = 1, Value2 = 2, Value3 = 3
            };

            AutoCSer.Metadata.MemberMap <DisabledMemberMap> serializeMemberMap = AutoCSer.Metadata.MemberMap <DisabledMemberMap> .NewEmpty();

#if DOTNET2
            serializeMemberMap.SetMember("Value1");                //添加成员 Value1
            serializeMemberMap.SetMember("Value2");                //添加成员 Value2
#else
            serializeMemberMap.SetMember(member => member.Value1); //添加成员 Value1
            serializeMemberMap.SetMember(member => member.Value2); //添加成员 Value2
#endif
            AutoCSer.BinarySerialize.SerializeConfig serializeMemberMapConfig = new AutoCSer.BinarySerialize.SerializeConfig {
                MemberMap = serializeMemberMap
            };

            byte[]            data     = AutoCSer.BinarySerializer.Serialize(value, serializeMemberMapConfig);
            DisabledMemberMap newValue = AutoCSer.BinaryDeSerializer.DeSerialize <DisabledMemberMap>(data);

            return(newValue != null && newValue.Value1 == 1 && newValue.Value2 == 2 && newValue.Value3 == 3);
        }