How do I deserialize XML without knowing the type beforehand?

后端 未结 3 1983
囚心锁ツ
囚心锁ツ 2020-12-11 01:38

Say I have a couple of basic objects like so:

[Serializable]
public class Base
{

    public string Property1 { get; set; }
    public int Property2 { get; s         


        
3条回答
  •  借酒劲吻你
    2020-12-11 02:04

    As far as I know, there is no simplier way to do this.

    I personally prefer a more generic solution (as I have to serialize a lot of various classes in my code): to keep type name serialized together with the value.

    You can take a look at this question for some details: Serialise to XML and include the type of the serialised object

提交回复
热议问题