本文整理汇总了C#中Instance.Serialise方法的典型用法代码示例。如果您正苦于以下问题:C# Instance.Serialise方法的具体用法?C# Instance.Serialise怎么用?C# Instance.Serialise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Instance
的用法示例。
在下文中一共展示了Instance.Serialise方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstanceSerialiseDeserialise
public void InstanceSerialiseDeserialise()
{
var originalInstance = new Instance()
{
Key = Guid.NewGuid(),
GroupKey = Guid.NewGuid(),
TargetKey = Guid.NewGuid(),
Name = "Test Instance",
Tags = new Dictionary<string, string>()
{
{ "tagKey", "Some tag value." },
{ "secondKey", "Multiline \r\n test!" }
}
};
Instance secondInstance;
using (var stream = originalInstance.Serialise())
{
secondInstance = new Instance(stream);
}
Assert.AreEqual(originalInstance.Key, secondInstance.Key);
Assert.AreEqual(originalInstance.GroupKey, secondInstance.GroupKey);
Assert.AreEqual(originalInstance.TargetKey, secondInstance.TargetKey);
Assert.AreEqual(originalInstance.Name, secondInstance.Name);
Assert.IsNotNull(secondInstance.Tags);
foreach (var tag in originalInstance.Tags)
{
Assert.IsTrue(secondInstance.Tags.ContainsKey(tag.Key));
Assert.AreEqual(tag.Value, secondInstance.Tags[tag.Key]);
}
}
示例2: InstanceSerialiseDeserialiseNullTags
public void InstanceSerialiseDeserialiseNullTags()
{
var originalInstance = new Instance()
{
Key = Guid.NewGuid(),
GroupKey = Guid.NewGuid(),
TargetKey = Guid.NewGuid(),
Name = "Test Instance",
};
Instance secondInstance;
using (var stream = originalInstance.Serialise())
{
secondInstance = new Instance(stream);
}
Assert.AreEqual(originalInstance.Key, secondInstance.Key);
Assert.AreEqual(originalInstance.GroupKey, secondInstance.GroupKey);
Assert.AreEqual(originalInstance.TargetKey, secondInstance.TargetKey);
Assert.AreEqual(originalInstance.Name, secondInstance.Name);
Assert.AreEqual(originalInstance.Tags.Count, secondInstance.Tags.Count);
}