そこにクラスとプロパティがあります。一部のプロパティは属性としてマークできます(これは私のLocalizedDisplayName
継承元ですDisplayNameAttribute
)。これは、クラスのすべてのプロパティを取得するためのメソッドです。
private void FillAttribute()
{
Type type = typeof (NormDoc);
PropertyInfo[] propertyInfos = type.GetProperties();
foreach (var propertyInfo in propertyInfos)
{
...
}
}
リストボックスLocalizedDisplayName
に属性の値をマークして表示するクラスのプロパティをリストボックスに追加したいと思います。これどうやってするの?
編集
これはLocalizedDisplayNameAttributeです:
public class LocalizedDisplayNameAttribute : DisplayNameAttribute
{
public LocalizedDisplayNameAttribute(string resourceId)
: base(GetMessageFromResource(resourceId))
{ }
private static string GetMessageFromResource(string resourceId)
{
var test =Thread.CurrentThread.CurrentCulture;
ResourceManager manager = new ResourceManager("EArchive.Data.Resources.DataResource", Assembly.GetExecutingAssembly());
return manager.GetString(resourceId);
}
}
リソースファイルから文字列を取得したい。ありがとう。
ToString()
ですか?質問を編集して、適用するカスタム属性のコードを追加し、必要なデータを指定できますか?