What exactly is Reflection and when is it a good approach?

前端 未结 11 1720
天命终不由人
天命终不由人 2020-12-25 14:58

What exactly is Reflection? I read the Wikipedia article on this subject and I understand that it is a kind of meta-programming, where the program can modify itself at run-

11条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-25 14:59

    I'll give you an example.

    As a programming exercise I wrote an mp3 file checker. It scans my music library and displays the id1/id2 tags I'm interested in in a DataGridView. I use reflection to get the properties from the mp3 info class without the UI code having to know anything about that class. If I want to change what information gets displayed I can either edit the mp3 info class or change its configuration (depending on how I wrote the class) and don't have to update the UI.

    It's also meant that I've been able to use Dependency Injection to use the same from end to display information about digital photographs just by swapping the data library class.

提交回复
热议问题