public static void createDictionary<T>(IEnumerable<T> myRecords)
where T: T.ID // Wont Compile
{
IDictionary<int, T> dicionario = myRecords.ToDictionary(r => r.ID);
foreach (var item in dicionario)
{
Console.WriteLine("Key = {0}",item.Key);
Type thisType = item.Value.GetType();
StringBuilder sb = new StringBuilder();
foreach (var itemField in thisType.GetProperties())
{
sb.AppendLine(string.Format("{0} = {1}", itemField.Name, itemField.GetValue(item.Value, null)));
}
Console.WriteLine(sb);
}
}
我怎么能强迫作为参数传递的类型所称的“ID”字段?
我建议物业ID的 “接口”使属性为只读而不是读/写;我很少想要一个ID属性是可写的。 –
@JonSkeet我正在考虑EF POCO课 – xanatos
我试图逃避宣布一个新的界面......我认为有一个解决方案的字段名称......但是,谢谢 –