Language: C#
IViewMetadata for gettting TypeIdentity of Export
namespace Nowcom.Quicksilver { using System.ComponentModel.Composition.Primitives; using System.Linq; using System; using System.ComponentModel.Composition.ReflectionModel; using System.Collections.Generic; public class WrappedPartDefinition: ComposablePartDefinition { ComposablePartDefinition _PartDefinition; Dictionary<string, object> _Metadata; public WrappedPartDefinition(ComposablePartDefinition partDefintion, Type type) { _PartDefinition = partDefintion; _Metadata = new Dictionary<string, object>(partDefintion.Metadata); _Metadata["TypeIdentity"] = type; } public override IEnumerable<ExportDefinition> ExportDefinitions { get { return _PartDefinition.ExportDefinitions; } } public override IEnumerable<ImportDefinition> ImportDefinitions { get { return _PartDefinition.ImportDefinitions; } } public override IDictionary<string, object> Metadata { get { return _Metadata; } } public override ComposablePart CreatePart() { return _PartDefinition.CreatePart(); } } public class MetadataCatalog : ComposablePartCatalog { ComposablePartCatalog _WrappedCatalog; public MetadataCatalog(ComposablePartCatalog wrappedCatalog) { if (wrappedCatalog == null) { throw new ArgumentNullException("wrappedCatalog"); } _WrappedCatalog = wrappedCatalog; } public override IQueryable<ComposablePartDefinition> Parts { get { return _WrappedCatalog.Parts.Select(p => TransformPart(p)); } } private ComposablePartDefinition TransformPart(ComposablePartDefinition definition) { Type type = ReflectionModelServices.GetPartType(definition).Value; var partDef = new WrappedPartDefinition(definition, type); return partDef; } protected override void Dispose(bool disposing) { if (disposing) { _WrappedCatalog.Dispose(); } base.Dispose(disposing); } } } namespace Nowcom.Quicksilver { using System.ComponentModel.Composition; using System.Windows; using System; using System.ComponentModel.Composition.ReflectionModel; using System.ComponentModel.Composition.Primitives; using System.Linq; using System.Collections.Generic; public interface IViewMetadata { Type TypeIdentity { get; } } [MetadataAttribute] [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public sealed class ViewAttribute : ExportAttribute, IViewMetadata { public ViewAttribute() : base(typeof(UIElement)) { } public Type TypeIdentity { get; set; } } } [Export] public class ViewContainer { [ImportMany(typeof(UIElement), AllowRecomposition = true)] public List<ExportFactory<UIElement, IViewMetadata>> Views { get; set; } }
Tags:
Description:
Glenn, Here is the code for my MetadataCatalog, WrappedPartDefinition, IViewMetadata, ViewAttribute and ViewContainer.
Views are imported but TypeIdentity in the Metadata is null. My WrappedPartDefintion is adding the type I can see it in the debugger.
Views are imported but TypeIdentity in the Metadata is null. My WrappedPartDefintion is adding the type I can see it in the debugger.
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

