How could Reflection not lead to code smells?

后端 未结 18 2132
失恋的感觉
失恋的感觉 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:28

    I've seen good usages with custom attributes. Such as a database framework.

    [DatabaseColumn("UserID")]
    [PrimaryKey]
    public Int32 UserID { get; set; }
    

    Reflection can then be used to get further information about these fields. I'm pretty sure LINQ To SQL does something similar...

    Other examples include test frameworks...

    [Test]
    public void TestSomething()
    {
        Assert.AreEqual(5, 10);
    }
    

提交回复
热议问题