必要な情報を取得する必要がある場合は、 afieldまたはproperties values/ names、
を使用しないとどうすればできますSystem.Reflectionか?
public class anyClass
{
public const string UserID = "usrID",
UserName = "usrName";
}
の使用を避けることができるかどうかを本当に知りたかったのでreflection、
私は少し調査を行いました..私の使命の正しい用語は
イントロスペクション を入力します(専用タグはここでは存在しませんSO)
Introspectionと混同しないでくださいreflection。
これはさらに一歩進んで、プログラムが値を操作する機能です。
メタデータ、propertiesおよび/または実行時functionsのobject。
システム リフレクションを使用すると、次のコード例のようにFields-にアクセスできます。values
var ac = new anyClass();
public List<string> anyClassFieldsValuesList()
{
// sorry this was the one for the class above
return typeof(anyClass).GetFields()
.Select(f =>f.GetValue(ac).ToString()).ToList<string>();
// this would do for nested class
// return typeof(anyClass).GetNestedTypes()
.First(t => String.Compare(t.Name, "anyNested", true) == 0)
.GetFields()
.Select(f => f.GetValue(ac).ToString())
.ToList<string>();
}
.net は、より安価な方法でその情報を取得するためのツールまたはその他のアプローチの使用法を提供してくれますか?