class Packet
{
public Action{get;set;}
}
class Action
{
string Type;
}
class ConcreteAction1 : Action
{
base.Type="ConcreteAction1";
}
class ConcreteAction2 : Action
{
base.Type="ConcreteAction2";
}
我收到Packet
包含来自类的各种派生类的Action
类,默认情况下每个ConcreteActions
都被反序列化为基类Action
,但我希望它们被反序列化为它们的实际类型(ConcreteAction1 ,ConcreteAction2
...)
有没有办法做到这一点?