c# 4.0 - Indexer Class and AutoMapper C# -


how map 2 indexer class automapper? need map 2 models have property use collectionitem type. tried use automapper. doesn't work. please see example indexer class below:

public class collectionitem {     private readonly ienumerable<string> _keys;     private readonly idictionary<string, ilist<item>> _relatedcontents;     private static readonly ilist<item> _emptylist = new list<item>();      public collectionitem(ienumerable<string> keys)     {         _keys = keys;         _relatedcontents = new dictionary<string, ilist<item>>();     }      public ilist<item> this[string key]     {                 {             if (!containskey(key))             {                 throw new keynotfoundexception("the given key not present in dictionary");             }             return _relatedcontents.containskey(key) ? _relatedcontents[key] : _emptylist;         }     }      public bool containskey(string key)     {         return !string.isnullorempty(key) && _keys.contains(key, stringcomparer.ordinalignorecase);     } } 

thanks!

you can write own custom type resolver:

class fromcollection {     private list<string> _items;      public int count      {         { return _items.count; }     }     public string this[int index]     {         { return _items[index]; }         set {              _items[index] = value;          }     }      public fromcollection()     {         _items = new list<string>(enumerable.repeat("", 10));     } }  class tocollection {     private list<string> _items;      public string this[int index]     {         { return _items[index]; }         set {              _items[index] = value;          }     }      public tocollection()     {         _items = new list<string>(enumerable.repeat("", 10));     } }  class indexertypeconverter : typeconverter<fromcollection, tocollection> {     protected override tocollection convertcore(fromcollection source)     {         tocollection result = new tocollection();          (int = 0; < source.count; i++)         {             result[i] = source[i];            }          return result;     } }  internal class program {     private static void main(string[] args)     {         mapper.createmap<fromcollection, tocollection>()             .convertusing<indexertypeconverter>();          var src = new fromcollection();         src[3] = "hola!";          var dst = mapper.map<tocollection>(src);         console.writeline();     } } 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -