Why is the use of reflection in .NET recommended?

后端 未结 9 670
再見小時候
再見小時候 2020-11-30 22:25

Is it definitely a good practice to use it?

What are some possible situations in a project that need reflection?

9条回答
  •  青春惊慌失措
    2020-11-30 22:46

    The very useful XmlSerialization class relies on reflection. You don't have to deal with reflection yourself to use serialization, the serialization classes invoke reflection themselves. But it helps to tag your code with Attributes that guide how objects are serialized. The serialization classes use reflection at runtime to read those attributes. In the end, the process seems almost magical, requiring very few lines of explicit coding in a application; it's reflection that makes that convenience possible.

    XmlSerialization itself is awesome not only because it is a very convenient way to create data files from an application, it's also a very easy means of generating human readable records of a program's internal data model for debugging purposes.

提交回复
热议问题