C#: instantiating classes from XML

前端 未结 8 923
情歌与酒
情歌与酒 2021-02-04 09:05

What I have is a collection of classes that all implement the same interface but can be pretty wildly different under the hood. I want to have a config file control which of the

8条回答
  •  甜味超标
    2021-02-04 09:28

    Reflection allows you to do that. You also may want to look at XML Serialization.

    Type type = blah.GetType();
    PropertyInfo prop = type.GetProperty("prop1");
    prop.SetValue(blah, "foo", null);
    

提交回复
热议问题