当前位置: 首页>>代码示例>>C#>>正文


C# Marshaller.Marshal方法代码示例

本文整理汇总了C#中Marshaller.Marshal方法的典型用法代码示例。如果您正苦于以下问题:C# Marshaller.Marshal方法的具体用法?C# Marshaller.Marshal怎么用?C# Marshaller.Marshal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Marshaller的用法示例。


在下文中一共展示了Marshaller.Marshal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestStructure

        public void TestStructure()
        {
            for (int i = 1; i <= RepeatCnt; i++)
            {
                Console.WriteLine(">>> Iteration started: " + i);

                // 1. Generate and shuffle objects.
                IList<BranchedType> objs = new List<BranchedType>();

                for (int j = 0; j < 6 * ObjectsPerMode; j++)
                    objs.Add(new BranchedType((j%6) + 1));

                objs = IgniteUtils.Shuffle(objs);

                // 2. Create new marshaller.
                BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(typeof(BranchedType));

                BinaryConfiguration cfg = new BinaryConfiguration
                {
                    TypeConfigurations = new List<BinaryTypeConfiguration> { typeCfg }
                };

                Marshaller marsh = new Marshaller(cfg);

                // 3. Marshal all data and ensure deserialized object is fine.
                foreach (BranchedType obj in objs)
                {
                    Console.WriteLine(">>> Write object [mode=" + obj.mode + ']');

                    byte[] data = marsh.Marshal(obj);

                    BranchedType other = marsh.Unmarshal<BranchedType>(data);

                    Assert.IsTrue(obj.Equals(other));
                }
                
                Console.WriteLine();

                // 4. Ensure that all fields are recorded.
                var desc = marsh.GetDescriptor(typeof (BranchedType));

                CollectionAssert.AreEquivalent(new[] {"mode", "f2", "f3", "f4", "f5", "f6", "f7", "f8"},
                    desc.WriterTypeStructure.FieldTypes.Keys);
            }
        }
开发者ID:dheep-purdessy,项目名称:ignite,代码行数:45,代码来源:BinaryStructureTest.cs

示例2: TestWriteRead

        public void TestWriteRead()
        {
            var marsh = new Marshaller(new BinaryConfiguration(typeof(ReadWriteAll)));

            marsh.Unmarshal<ReadWriteAll>(marsh.Marshal(new ReadWriteAll()));
        }
开发者ID:vladisav,项目名称:ignite,代码行数:6,代码来源:BinaryReaderWriterTest.cs


注:本文中的Marshaller.Marshal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。