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

前端 未结 11 1721
天命终不由人
天命终不由人 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 15:05

    Another example: I have code that I use that takes the output of a database - which is a set of rows with named columns - and feeds it into an array of objects. I iterate through the rows, and if the target object has a property with the same name and type, I set it. This makes for my data-getting code just looking something like this:

    SqlDataReader sdr = Helper.GetReader("GetClientByID", ClientID);
    Client c = new Client();
    FillObject(sdr, c);
    return c;
    

提交回复
热议问题