Как установить ExportMetaData с несколькими значениями, а также с одним настраиваемым атрибутом?

У меня есть следующие атрибуты ExportMetaData, установленные для моего класса:

  [Export(typeof(IDocumentViewer))]
  [ExportMetadata("Name", "MyViewer")]
  [ExportMetadata("SupportsEditing", true)]
  [ExportMetadata("Formats", DocFormat.DOC, IsMultiple = true)]
  [ExportMetadata("Formats", DocFormat.DOCX, IsMultiple = true)]
  [ExportMetadata("Formats", DocFormat.RTF, IsMultiple = true)]  

У меня также есть поддерживающий интерфейс:

  public interface IDocumentViewerMetaData {
    /// <summary>
    /// Gets the format.
    /// </summary>
    /// <value>The format.</value>
    IEnumerable<DocFormat> Formats { get; }
    /// <summary>
    /// Gets the name of the viewer
    /// </summary>
    /// <value>The name.</value>
    string Name { get; }
    /// <summary>
    /// Gets a value indicating whether this viewer supports editing
    /// </summary>
    /// <value><c>true</c> if [supports editing]; otherwise, <c>false</c>.</value>
    bool SupportsEditing { get; }
  }

И, конечно же, мой ImportMany:

[ImportMany(typeof(IDocumentViewer))]
public IEnumerable<Lazy<IDocumentViewer, IDocumentViewerMetaData>> _viewers { get; set; }

Я бы хотел использовать строго типизированный класс атрибутов вместо использования атрибута ExportMetaData. Я не нашел способа сделать это, одновременно поддерживая одиночные значения (Name, SupportsEditing, в приведенном выше примере).

Я предполагаю сделать что-то похожее на следующее (или что-то, что предлагается как лучшее):

[Export(typeof(IDocumentViewer))]
[DocumentViewerMetadata(Name = "MyViewer")]
[DocumentViewerMetadata(SupportsEditing = true)]
[DocumentViewerMetadata(Format = DocFormat.DOC)]
[DocumentViewerMetadata(Format = DocFormat.DOCX)]

Я почти уверен, что способ сделать это ЕСТЬ, просто я не нашел правильного способа соединить точки. :)

13
задан Seph 27 March 2012 в 08:33
поделиться