たとえば、タイプ Employee のオブジェクトのプロパティを動的に参照するにはどうすればよいですか? 私は次のようなものを求めていemployee."hasBeenPaid"
ますか?それは反射を伴いますか?
class Employee
{
String name;
Bool hasBeenPaid;
}
たとえば、タイプ Employee のオブジェクトのプロパティを動的に参照するにはどうすればよいですか? 私は次のようなものを求めていemployee."hasBeenPaid"
ますか?それは反射を伴いますか?
class Employee
{
String name;
Bool hasBeenPaid;
}
あなたは試すことができます:
Type type = your_class.GetType();
PropertyInfo propinfo = type.GetProperty("hasBeenPaid");
値が必要な場合
value = propinfo.GetValue(your_class, null);
動的 C# 機能を使用できます。はい、実行時にリフレクションを使用してプロパティを解決します。