コード例 #1
0
        public void CanReadListMember()
        {
            using (var stream = new MemoryStream())
            {
                WithStruct            value1   = new WithStruct(161, 321, 641);
                WithStruct            value2   = new WithStruct(162, 322, 642);
                WithStruct            value3   = new WithStruct(163, 323, 643);
                WithList <WithStruct> expected = new WithList <WithStruct>()
                {
                    Values = new List <WithStruct>()
                    {
                        value1, value2, value3
                    }
                };
                using (var bw = new BinaryWriter(stream, Encoding.Default, true))
                {
                    expected.WriteTo(bw);
                }
                stream.Position = 0;

                var formatBuilder = Bin.Format()
                                    .Includes <WithList <WithStruct> >(cfg => cfg.Read(t => t.Values, lcfg => lcfg.LastElementWhen(c => c.Index > 2)))
                                    .Includes <WithStruct>();

                var format = formatBuilder.Build <WithList <WithStruct> >();
                var actual = format.Read(stream);

                Assert.AreEqual(expected, actual);
            }
        }
コード例 #2
0
        public void CanReadArrayMember()
        {
            using (var stream = new MemoryStream())
            {
                WithStruct value1   = new WithStruct(161, 321, 641);
                WithStruct value2   = new WithStruct(162, 322, 642);
                WithStruct value3   = new WithStruct(163, 323, 643);
                WithArray  expected = new WithArray()
                {
                    FixedLegthArray = new[] { value1, value2 },
                    VarLength       = 1,
                    VarLegthArray   = new[] { value3 }
                };
                using (var bw = new BinaryWriter(stream, Encoding.Default, true))
                {
                    expected.WriteTo(bw);
                }
                stream.Position = 0;

                var formatBuilder = Bin.Format()
                                    .Includes <WithArray>(cfg => cfg
                                                          .Read(t => t.FixedLegthArray, acfg => acfg.Length(2))
                                                          .Read(t => t.VarLegthArray, acfg => acfg.Length(ctx => ctx.Object.VarLength)))
                                    .Includes <WithStruct>();

                var format = formatBuilder.Build <WithArray>();
                var actual = format.Read(stream);

                Assert.AreEqual(expected, actual);
            }
        }
コード例 #3
0
ファイル: OopClasses.cs プロジェクト: AnnaSava/MetanitSharp
        public static void Display()
        {
            WithStruct <int>               gen1 = new WithStruct <int>();
            WithClass <Person>             gen2 = new WithClass <Person>();
            WithPublicConstructor <Person> gen3 = new WithPublicConstructor <Person>();

            Console.WriteLine(gen1.GetType());
            Console.WriteLine(gen2.GetType());
            Console.WriteLine(gen3.GetType());

            Transaction <Account> transaction = new Transaction <Account>();

            Console.WriteLine(transaction.GetType());
        }
コード例 #4
0
ファイル: MemberReading.cs プロジェクト: maxibrain/fluentbin
        public void CanReadByCondition()
        {
            using (var stream = new MemoryStream())
            {
                var expected = new WithStruct(16, 32, 64);
                using (var bw = new BinaryWriter(stream, Encoding.Default, true))
                {
                    expected.WriteTo(bw);
                }
                stream.Position = 0;

                var formatBuilder = Bin.Format()
                                    .Includes <WithStruct>(cfg => cfg.Read(c => c.Int64Value, builder => builder.If(c => false)));

                var format = formatBuilder.Build <WithStruct>();
                var actual = format.Read(stream);

                Assert.AreEqual(expected, actual);
            }
        }