2
Vote

Maping by Dictionary<K,V> BUG?

description

/ Code /
public class ObjectItemA
{
    public string Name { get; set; }
}

public class ObjectItemB
{
    public string Name { get; set; }
}

public class Program
{
    static void Main(string[] args)
    {
        Dictionary<uint, ObjectItemA> a = new Dictionary<uint, ObjectItemA>();
        a.Add(1, new ObjectItemA { Name = "HAHA" });
        Dictionary<uint, ObjectItemB> b = ObjectMapperManager.DefaultInstance.GetMapper<Dictionary<uint, ObjectItemA>, Dictionary<uint, ObjectItemB>>().Map(a);
        Console.WriteLine("a.Count = " + a.Count);
        Console.WriteLine("b.COunt = " + b.Count);
    }
}
/ Console /
a.Count = 1
b.COunt = 0


Please help me

comments

hin_longkid wrote Jun 22, 2014 at 7:00 PM

In your code, variable "a" is not a value type, and it has no field or property name match with emitmapper's DefaultMapConfig.
you can try this, but the Dictionary<K, V> V can not be a class or something complex, :P
    public class A
    {
        public Dictionary<uint, object> ObjectItemAs { get; set; }
    }

    public class B
    {
        public Dictionary<uint, object> ObjectItemAs { get; set; }
    }

   var a = new A
   {
       ObjectItemAs = new Dictionary<uint, object> { {1, 12} }
   };
   
   var b = ObjectMapperManager.DefaultInstance.GetMapper<A, B>().Map(a);

mmk5 wrote Jun 23, 2014 at 2:25 AM

Thank you for your reply, although has been almost a year..