2011-11-04 65 views
0

我喜歡使用自定義的IDictionary類我DynamicComponent映射:如何使用自定義詞典類的DynamicComponent映射

class ObservableDictionary : Hashtable, INotifyCollectionChanged, INotifyPropertyChanged 

映射列表時有可能按如下方式使用自定義集合類型:

mapping.HasMany(x => x.Items).CollectionType<ObservableCollection<ItemClass>>(); 

但我怎麼能用DynamicComponents做到這一點?沒有CollectionType方法。

mapping.DynamicComponent(
    x => x.DynamicFields, 
    c => { 
      c.Map(x => x["fld_num"]).CustomType(typeof(int)); 
      c.Map(x => x["shortdesc"]).CustomType(typeof(string)); 
     }); 

回答

0

如果您的自定義詞典的內辭典保持數據,那麼你可以

mapping.Component(x => x.DynamicFields, c => c.DynamicComponent(
    Reveal.Member<CustomDictionary, IDictionary>("_innerDictionary"), 
    c => { 
     c.Map(x => x["fld_num"]).CustomType(typeof(int)); 
     c.Map(x => x["shortdesc"]).CustomType(typeof(string)); 
    }) 
);