本文整理汇总了C#中Unpacker.Unpack方法的典型用法代码示例。如果您正苦于以下问题:C# Unpacker.Unpack方法的具体用法?C# Unpacker.Unpack怎么用?C# Unpacker.Unpack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Unpacker
的用法示例。
在下文中一共展示了Unpacker.Unpack方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSimplePropertyPackUnpack
public void TestSimplePropertyPackUnpack()
{
using (IBuffer buffer = new SimpleBuffer())
{
RawDataSerializer ms = new RawDataSerializer(buffer);
BinaryPackager packer = new BinaryPackager();
RegisteredPackageDefinition registeredPackageDefinition;
packer.RegisterDefinition(new PackageDefinition<PackData>()
.Define(x => x.IntData, x => x.IntData)
.Define(x => x.StringData, x => x.StringData)
.Define(x => x.DateTimeData, x => x.DateTimeData), out registeredPackageDefinition);
var packData = new PackData()
{
ArrayPackData = null,
DateTimeData = DateTime.Now,
IntData = 124,
StringData = "Some String",
};
packer.Pack(packData, ms);
using (StreamDeserilizer deserilizer = new StreamDeserilizer(buffer.Buffer))
{
Unpacker unpacker = new Unpacker();
unpacker.AddPackageDefinition(new EmptyConstractorUnpackageDefinition<PackData>()
{
DefinitionId = registeredPackageDefinition.DefinitionId
}
.DefineInt("IntData", (data, i) => data.IntData = i)
.DefineString("StringData", (data, s) => data.StringData = s)
.DefineDateTime("DateTimeData",
(data, time) => data.DateTimeData = time));
var unpackData = unpacker.Unpack<PackData>(deserilizer);
Assert.IsNotNull(unpackData);
CheckValidPackData(packData, unpackData);
Assert.AreEqual(packData.ArrayPackData, unpackData.ArrayPackData);
}
}
}
示例2: TestArrayWithSimplePropertyPackUnpack
public void TestArrayWithSimplePropertyPackUnpack()
{
using (IBuffer buffer = new SimpleBuffer())
{
RawDataSerializer ms = new RawDataSerializer(buffer);
BinaryPackager packer = new BinaryPackager();
RegisteredPackageDefinition registeredPackageDefinition;
packer.RegisterDefinition(new PackageDefinition<PackData>()
.Define(x => x.IntData, x => x.IntData)
.Define(x => x.StringData, x => x.StringData)
.Define(x => x.ArrayPackData, x => x.ArrayPackData)
.Define(x => x.DateTimeData, x => x.DateTimeData), out registeredPackageDefinition);
var packData = new PackData()
{
ArrayPackData = new List<PackData>()
{
new PackData()
{
IntData =1,
StringData = "First String",
},
new PackData()
{
IntData =2,
DateTimeData = DateTime.Now + TimeSpan.FromHours(2),
ArrayPackData = new List<PackData>(),
},
new PackData()
{
StringData = string.Empty
},
},
DateTimeData = DateTime.Now,
IntData = 124,
StringData = "Some String",
};
packer.Pack(packData, ms);
using (StreamDeserilizer deserilizer = new StreamDeserilizer(buffer.Buffer))
{
Unpacker unpacker = new Unpacker();
unpacker.AddPackageDefinition(new EmptyConstractorUnpackageDefinition<PackData>()
{
DefinitionId = registeredPackageDefinition.DefinitionId
}
.DefineInt("IntData", (data, i) => data.IntData = i)
.DefineString("StringData", (data, s) => data.StringData = s)
.DefineEnumerable("ArrayPackData",
(data, enumerable) => data.ArrayPackData = enumerable.NullGurd(x => x.OfType<PackData>().ToList()))
.DefineDateTime("DateTimeData", (data, time) => data.DateTimeData = time));
var unpackData = unpacker.Unpack<PackData>(deserilizer);
Assert.IsNotNull(unpackData);
CheckValidPackData(unpackData, packData);
Assert.IsNotNull(packData.ArrayPackData);
Assert.AreEqual(3, packData.ArrayPackData.Count);
CheckValidPackData(packData.ArrayPackData[0], unpackData.ArrayPackData[0]);
Assert.IsNull(unpackData.ArrayPackData[0].ArrayPackData);
CheckValidPackData(packData.ArrayPackData[1], unpackData.ArrayPackData[1]);
Assert.IsNotNull(unpackData.ArrayPackData[1].ArrayPackData);
Assert.AreEqual(0, unpackData.ArrayPackData[1].ArrayPackData.Count);
CheckValidPackData(packData.ArrayPackData[2], unpackData.ArrayPackData[2]);
Assert.IsNull(unpackData.ArrayPackData[2].ArrayPackData);
}
}
}
示例3: TestInstanceCreatorPackUnpack
public void TestInstanceCreatorPackUnpack()
{
using (IBuffer buffer = new SimpleBuffer())
{
RawDataSerializer ms = new RawDataSerializer(buffer);
BinaryPackager packer = new BinaryPackager();
RegisteredPackageDefinition registeredPackageDefinition;
packer.RegisterDefinition(new PackageDefinition<PackData>(), out registeredPackageDefinition);
packer.Pack(new PackData(), ms);
using (StreamDeserilizer deserilizer = new StreamDeserilizer(buffer.Buffer))
{
Unpacker unpacker = new Unpacker();
unpacker.AddPackageDefinition(new EmptyConstractorUnpackageDefinition<PackData>() { DefinitionId = registeredPackageDefinition.DefinitionId });
Assert.IsNotNull(unpacker.Unpack<PackData>(deserilizer));
}
}
}