मैं निम्नलिखित ExportMetaData मेरी कक्षा पर सेट विशेषताओं है:एकाधिक मानों के साथ-साथ एकल w/कस्टम विशेषता के साथ ExportMetaData को कैसे सेट करें?
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:
[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)]
मैं भी एक समर्थन इंटरफेस हो
[ImportMany(typeof(IDocumentViewer))]
public IEnumerable<Lazy<IDocumentViewer, IDocumentViewerMetaData>> _viewers { get; set; }
मैं क्या होगा ऐसा करने के लिए ExportMetaData विशेषता का उपयोग करने के बजाय दृढ़ता से टाइप की गई विशेषता वर्ग का उपयोग करना है। मैंने इसे करने के लिए एक तरीका नहीं निकाला है, जबकि एकल मानों का समर्थन भी करता है (नाम, समर्थन उदाहरण, ऊपर दिए गए उदाहरण में)।
मैं निम्नलिखित समान कुछ कर रही कल्पना (या जो भी सबसे अच्छा के रूप में सुझाव दिया है):
[Export(typeof(IDocumentViewer))]
[DocumentViewerMetadata(Name = "MyViewer")]
[DocumentViewerMetadata(SupportsEditing = true)]
[DocumentViewerMetadata(Format = DocFormat.DOC)]
[DocumentViewerMetadata(Format = DocFormat.DOCX)]
मैं काफी कुछ ऐसा करने के लिए एक तरीका होता है कि कर रहा हूँ, मैं तो बस के लिए सही रास्ता नहीं मिला है बिंदुओ को जोडो। :)
मैथ्यू - धन्यवाद !! मैं आपके द्वारा किए गए परिवर्तनों को समझता हूं और वास्तव में उन्हें पसंद करता हूं - कक्षाओं पर लागू होने के लिए कम विशेषताओं, साथ ही कुछ अतिरिक्त प्रकार-सुरक्षा (इंटरफ़ेस को कार्यान्वित करना)। इसके अलावा, अब मुझे पता है कि मैं कई वस्तुओं में गुजरने में सक्षम होने के कारण क्या खो रहा था .. पैरा []! मैं आपके समाधान के बहुत करीब था, लेकिन उस छोटे बिंदु को याद किया। आपके उत्कृष्ट उत्तर के लिए बहुत बहुत धन्यवाद। –