本文整理汇总了C#中Marshaller.GetDescriptor方法的典型用法代码示例。如果您正苦于以下问题:C# Marshaller.GetDescriptor方法的具体用法?C# Marshaller.GetDescriptor怎么用?C# Marshaller.GetDescriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Marshaller
的用法示例。
在下文中一共展示了Marshaller.GetDescriptor方法的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: 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.
// Use single stream to test object offsets
using (var stream = new BinaryHeapStream(128))
{
var writer = marsh.StartMarshal(stream);
foreach (var obj in objs)
{
Console.WriteLine(">>> Write object [mode=" + obj.mode + ']');
writer.WriteObject(obj);
}
stream.Seek(0, SeekOrigin.Begin);
var reader = marsh.StartUnmarshal(stream);
foreach (var obj in objs)
{
var other = reader.ReadObject<BranchedType>();
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);
}
}