本文整理汇总了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);
}
}
示例2: TestWriteRead
public void TestWriteRead()
{
var marsh = new Marshaller(new BinaryConfiguration(typeof(ReadWriteAll)));
marsh.Unmarshal<ReadWriteAll>(marsh.Marshal(new ReadWriteAll()));
}