私は今解決策を見つけたと思います。
Page_Loadイベント内から以下を実行すると、Resourceクラス名が得られました。
String[] resourceClassNames = (from type in assembly.GetTypes()
where type.IsClass && type.Namespace.Equals("Resources")
select type.Name).ToArray();
そのため、TypeConverterのGetResourceFileNames(ITypeDescriptorContext context)関数内から、コンテキストパラメーターを使用して正しいアセンブリを取得することで、同様のことができると思いました。残念ながら、カスタムコントロールのアセンブリまたはSystem.Webアセンブリしか取得できなかったようです。
そのため、代わりに、EditValueルーチンにIServiceProviderが渡されるUITypeEditorを作成しました。これから、ITypeDiscoveryServiceのインスタンスを作成することができました。これを使用して、正しいアセンブリからすべての型を取得しました。
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
// Check if all the expected parameters are here
if (context == null || context.Instance == null || provider == null)
{
// returning with the received value
return base.EditValue(context, provider, value);
}
// Create the Discovery Service which will find all of the available classes
ITypeDiscoveryService discoveryService = (ITypeDiscoveryService)provider.GetService(typeof(ITypeDiscoveryService));
// This service will handle the DropDown functionality in the Property Grid
_wfes = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
// Create the DropDown control for displaying in the Properties Grid
System.Windows.Forms.ListBox selectionControl = new System.Windows.Forms.ListBox();
// Attach an eventhandler to close the list after an item has been selected
selectionControl.SelectedIndexChanged += new EventHandler(selectionControl_SelectedIndexChanged);
// Get all of the available types
ICollection colTypes = discoveryService.GetTypes(typeof(object), true);
// Enumerate the types and add the strongly typed
// resource class names to the selectionControl
foreach (Type t in colTypes)
{
if (t.IsClass && t.Namespace.Equals("Resources"))
{
selectionControl.Items.Add(t.Name);
}
}
if (selectionControl.Items.Count == 0)
{
selectionControl.Items.Add("No Resources found");
}
// Display the UI editor combo
_wfes.DropDownControl(selectionControl);
// Return the new property value from the UI editor combo
if (selectionControl.SelectedItem != null)
{
return selectionControl.SelectedItem.ToString();
}
else
{
return base.EditValue(context, provider, value);
}
}
void selectionControl_SelectedIndexChanged(object sender, EventArgs e)
{
_wfes.CloseDropDown();
}
これはうまくいくようですが、LinQを使用して必要な型を取得するためのよりスタイリッシュな方法があると思いますが、LinQを調べ始めたばかりであり、コレクションに対してクエリを実行するときに正しい構文を取得できないようです。前の例のように配列。
誰かがこれを行うLinQ構文、または実際にすべてを達成するためのより良い方法を提案できるなら、それは大歓迎です。