Учитывая следующий код, я не могу вернуть словарь.
[JsonProperty]
public virtual IDictionary<Product, int> JsonProducts
{
get
{
return Products.ToDictionary<Product, int>(x => x.Key, v => v.Value);
}
}
public virtual IDictionary<Product, int> Products { get; set; }
Я получаю следующие ошибки ..
'System.Collections.Generic.IDictionary' не содержат определение для 'ToDictionary', а перегрузка лучшего метода расширения 'System.Linq.Enumerable.ToDictionary (System.Collections.Generic.IEnumerable, System.Func, System.Collections.Generic.IEqualityComparer)' имеет некоторые недопустимые аргументы
не может преобразовать «лямбда-выражение» в «System.Func»
не может преобразовать из «лямбда-выражение» в «System.Collections.Generic.IEqualityComparer
В классе Product нет ничего особенного. он просто определяется как
class Product
{
public virtual int Id { get; set; }
public virtual String Name { get; set; }
}