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();
}
现在,我希望类套件是可序列化的。这里的问题是:

  • XMl序列化基本上用于将数据序列化为某种对象,因此基本上可以序列化/反序列化有状态属性,这很好

  • 这个将要序列化的特定类包含Plugin类型(包含包含一些属性值的属性组合)+functionasts

  • 这意味着我需要使用factory来获取对象的真实实例,以便插件能够使用它的所有功能和属性值


  • 我是在看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中,服务将由工厂提供。但是需要一种方法将它们相互绑定我认为实现这个接口可以让你做到这一点。你能为这个接口画一个蓝图签名吗?