First of all I know that the title is not so good but the thing is I dont even know how to explain my question; I'll just show an example below on what I'm trying to do:
EDIT: I should have given a better example to begin with; let's try again:
// MyAppComponentModel.dll
namespace MyAppComponentModel {
using System.Collections;
interface IResource { }
interface IStringResource : IResource { }
interface IIconResource : IResource { }
interface IDialogResource : IResource { }
interface IResourceProvider {
void GetResource<T>(out T result, IDictionary criteria = null) where T : IResource;
}
}
// ThirdPartyLib.dll
namespace ResourceProviderLibA {
using System.Collections;
using System.ComponentModel.Composition;
using MyAppComponentModel.
public sealed class StringResource : IStringResource { ... }
public sealed class IconResource : IIconResource { ... }
[Export(typeof(IResourceProvider))]
public sealed class StringAndIconResourceProvider : IResourceProvider {
void IResourceProvider.Get<T>(out T result, IDictionary criteria) {
if (typeof(T) == typeof(IDialogResource))
throw new NotSupportedException();
this.InternalGet(out result, criteria);
}
void InternalGet(out IStringResource result, IDictionary criteria) {
result = new StringResource();
...
}
void InternalGet(out IIconResource result, IDictionary criteria) {
result = new IconResource();
...
}
}
}
// MyMefTestApp.exe
namespace MyMefTestApp {
using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting;
using MyAppComponentModel.
static class Program {
[ImportMany(typeof(IResourceProvider))]
private IEnumerable<IResourceProvider> mProviders;
static void Main(String[] args) {
foreach (var provider in this.mProviders) {
...
}
}
}
}
I know it's somehow possible and I strongly believe I did something like this once just dont remember how. Anyone?
I already know that this can be done via Reflection so please skip those solutions - thanks.