How could Reflection not lead to code smells?

后端 未结 18 2125
失恋的感觉
失恋的感觉 2020-12-12 15:02

I come from low level languages - C++ is the highest level I program in.

Recently I came across Reflection, and I just cannot fathom how it could be used without cod

18条回答
  •  盖世英雄少女心
    2020-12-12 15:21

    It is all about rapid development.

    var myObject = // Something with quite a few properties.
    var props = new Dictionary();
    foreach (var prop in myObject.GetType().GetProperties())
    {
        props.Add(prop.Name, prop.GetValue(myObject, null);
    }
    

提交回复
热议问题