我有一个包含大量属性的类。其中大多数是自定义类型。我想获取所有那些接口(interface)类型相同的属性。
Public class abc:IamLegend
{
few properties
}
public class def:IamLegend
{
few properties
}
public class on_which_iamworking
{
public abc propabc{ get; set; }
public def propdef{ get; set; }
public someothertype propother{ get; set; }
}
我想要返回 propabc 和 propdef 的东西。
我知道如何使用反射来做到这一点,但我正在寻找另一种方法。
我正在使用 C# 4.0
谢谢
最佳答案
恐怕如果不使用反射,这在运行时是不可能的。这就是反射的设计目的。
关于c# - 如何在不使用反射的情况下获取类中指定类型的所有属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8667312/