とにかくクラスプロパティの名前を得ることができますIntProperty
?クラスプロパティの名前を取得するには?
public class ClassName
{
public static int IntProperty { get { return 0; } }
}
//something like below but I want to get the string of "IntProperty"
ClassName.IntProperty.GetType().Name
は基本的に私が何をしたいのか、動的にデータベースにプロパティ名の文字列を保存し、後で上のデータベースから取得し、プロパティを動的に呼び出すことがあります。
私が探しているものは、ダックタイピングと似ていると思います。
ありがとうございます!
更新:
これは実際のコードです。これはワークフローのようなものです。しかし、各タスクはクラスのプロパティとして定義されます(クラスはタスクをグループ化するために使用されます)。 namespace.ApplicationTask.SendIncompleteNotification
とデータベースにこれを保存します。
public class ApplicationTask
{
public static Task<string> SendIncompleteNotification
{
get
{
return new Task<string>
(
a => Console.WriteLine("Sample Task")
, "This is a sample task which does nothing."
);
}
}
}
ので、コードは次のようにクラスとプロパティ何かの完全な名前を取得することができるようになります。後で、コードは文字列を読み取り、動的にタスクを作成し、別のタスクに渡して実行します。
によってそれを得ることができます。http://stackoverflow.com/questions/579963/can-i- get-specific-funct-objectからのメタデータ http://stackoverflow.com/questions/301809/workarounds-for-nameof-operator-in-c-typesafe-databinding – nawfal
[メソッド名の取得ラムダ式を使って入力してください](http://stackoverflow.com/questions/273941/g et-method-name-and-type-using-lambda-expression) – nawfal