Managed Extensibility 프레임 워크를 사용하여 방금 놀았습니다. 내 보낸 수업 및 가져 오기 진술 있어요 :ImportMany 및 ExportMetadata를 사용하는 MEF
[Export(typeof(IMapViewModel))]
[ExportMetadata("ID",1)]
public class MapViewModel : ViewModelBase, IMapViewModel
{
}
[ImportMany(typeof(IMapViewModel))]
private IEnumerable<IMapViewModel> maps;
private void InitMapView()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(ZoneDetailsViewModel).Assembly));
CompositionContainer container = new CompositionContainer(catalog);
container.ComposeParts(this);
foreach (IMapViewModel item in maps)
{
MapView = (MapViewModel)item;
}
}
이것은 잘 작동합니다. IEnumerable은 내 보낸 클래스를 가져옵니다. 아니오 나는 (이전과 같은 수출) 내가 필요로하는 클래스를 필터링 할 수 있도록이 IEnumerable에서에 요소가없는 한이 게으른 목록을 사용하여 메타 데이터를 포함하는
[ImportMany(typeof(IMapViewModel))]
private IEnumerable<Lazy<IMapViewModel,IMapMetaData>> maps;
private void InitMapView()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(ZoneDetailsViewModel).Assembly));
CompositionContainer container = new CompositionContainer(catalog);
container.ComposeParts(this);
foreach (Lazy<IMapViewModel,IMapMetaData> item in maps)
{
MapView = (MapViewModel)item.Value;
}
}
을 변경하려고합니다. 어딘가에서 분명하고 어리석은 실수를 범했다고 생각합니다.
메타 데이터 인터페이스는 어떤 모습입니까? –
메타 데이터를 포함하여 ImportMany를 수행 할 수 있는지 여부를 몰랐습니다. 좋은! – juFo