本文整理汇总了C#中Serializer.ForObject方法的典型用法代码示例。如果您正苦于以下问题:C# Serializer.ForObject方法的具体用法?C# Serializer.ForObject怎么用?C# Serializer.ForObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serializer
的用法示例。
在下文中一共展示了Serializer.ForObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldDoSurrogateObjectSwapTwoTimes
public void ShouldDoSurrogateObjectSwapTwoTimes()
{
var b = new SurrogateMockB();
var serializer = new Serializer(GetSettings());
serializer.ForObject<SurrogateMockB>().SetSurrogate(x => new SurrogateMockA(1));
serializer.ForSurrogate<SurrogateMockA>().SetObject(x => new SurrogateMockC());
for(var i = 0; i < 2; i++)
{
using(var stream = new MemoryStream())
{
serializer.Serialize(b, stream);
stream.Seek(0, SeekOrigin.Begin);
var pseudocopy = serializer.Deserialize<object>(stream);
var c = pseudocopy as SurrogateMockC;
Assert.IsNotNull(c);
}
}
}
示例2: ShouldThrowWhenSettingSurrogatesAfterSerialization
public void ShouldThrowWhenSettingSurrogatesAfterSerialization()
{
var serializer = new Serializer(SettingsFromFields);
serializer.Serialize(new object(), Stream.Null);
Assert.Throws<InvalidOperationException>(() => serializer.ForObject<object>().SetSurrogate(x => new object()));
}
示例3: EmulationManager
private EmulationManager()
{
var settings = new Antmicro.Migrant.Customization.Settings(Antmicro.Migrant.Customization.Method.Generated, Antmicro.Migrant.Customization.Method.Generated,
Antmicro.Migrant.Customization.VersionToleranceLevel.AllowFieldAddition
| Antmicro.Migrant.Customization.VersionToleranceLevel.AllowFieldRemoval
| Antmicro.Migrant.Customization.VersionToleranceLevel.AllowGuidChange
| Antmicro.Migrant.Customization.VersionToleranceLevel.AllowAssemblyVersionChange);
serializer = new Serializer(settings);
serializer.ForObject<PythonDictionary>().SetSurrogate(x => new PythonDictionarySurrogate(x));
serializer.ForSurrogate<PythonDictionarySurrogate>().SetObject(x => x.Restore());
currentEmulation = new Emulation();
ProgressMonitor = new ProgressMonitor();
stopwatch = new Stopwatch();
}