C# 序列化有状态的引用+;无状态对象
这是一种设计问题:C# 序列化有状态的引用+;无状态对象,c#,.net,xml,serialization,factory,C#,.net,Xml,Serialization,Factory,这是一种设计问题: class Suite { List<Plugins> Plugins {get;set;} } class DataCollector : Plugin { string Property1 {get;set;} string Property2 {get;set;} public void PrintMyName(); } class Measurement: Plugin { string Property1 {get;s
class Suite
{
List<Plugins> Plugins {get;set;}
}
class DataCollector : Plugin
{
string Property1 {get;set;}
string Property2 {get;set;}
public void PrintMyName();
}
class Measurement: Plugin
{
string Property1 {get;set;}
string Property2 {get;set;}
public void PrintMyName();
}
类套件
{
列出插件{get;set;}
}
类数据收集器:插件
{
字符串属性1{get;set;}
字符串属性2{get;set;}
public void PrintMyName();
}
类度量:插件
{
字符串属性1{get;set;}
字符串属性2{get;set;}
public void PrintMyName();
}
现在,我希望类套件是可序列化的。这里的问题是:
我是在看XMLSrializable+工厂组合吗?有什么好的优雅方法可以实现这一点吗?为什么不实现
IDeserializationCallback
接口,这样在反序列化时,您就可以通过调用工厂使对象恢复生命
我不太明白你们课程的目的,但我会尽我所能举一个例子:
public class MyDataClass : IDeserializationCallback
{
public int SimpleKeyProperty { get; set; }
public string TextProperty{ get; set; }
public void OnDeserialization(object sender)
{
//upon deserialization use the int key to get the latest value from
//factory (this is make believe...)
TextProperty = SomeFactory.GetCurrentValue( this.SimpleKeyProperty) ;
}
}
什么是“功能主义者”?另外,最好不要在MS Word中键入您的代码,因为不应该大写的关键字不幸被大写。(
类
,公共
,无效
,等等)我正在考虑将类分为两部分进行DTO+服务。这意味着DTO将被转储到XML中,服务将由工厂提供。但是需要一种方法将它们相互绑定我认为实现这个接口可以让你做到这一点。你能为这个接口画一个蓝图签名吗?