I have a MEF MetadataAttribute:
[MetadataAttribute]
[AttributeUsage]
public class MyTestAttribute : ExportAttribute, IMyTest
{
public MyTestAttribute(string pluginInfo)
{
_pluginInfo = pluginInfo;
}
string _pluginInfo;
public string PluginInfo{get{return _pluginInfo;}}
public override string ToString()
{
return PluginInfo;
}
}
public interface IMyTest
{
string PluginInfo{get;}
}
I have some other metadata attributes which inherits from other interfaces. All my attributes overrides ToString()
. I am using the method below to get plugins:
public void GetPlugins<TSender, TEventArgs, TAttributeMetadata>()
{
var importedPlugins = _container.GetExports<Action<TSender, TEventArgs>, TAttributeMetadata>(contract);
foreach(var plugin in importedPlugins)
{
string pluginInfo = plugin.Metadata.ToString();//this here is not
//returning plugin info. It is returning some kind of Guid and the interface name
//I could retrieve the pluginInfo via reflection but I don't want.
}
}
My question is why ToString()
is not returning the pluginInfo? What should I do to get pluginInfo? is it possible without reflection or dynamics?
Any help appreciated!