【发布时间】:2011-05-31 02:24:38
【问题描述】:
我正在使用 T4 template 为我的每个数据实体创建 DTO,但是使用 IList 时它失败了。
Func<PropertyInfo, bool> scalarProperties = p => !p.PropertyType.GetInterfaces().Any(t => t == typeof(System.Collections.IList) || t == typeof(System.Collections.ICollection));
Func<PropertyInfo, bool> collectionProperties = p => !scalarProperties.Invoke(p);
和
private bool ExportProperty(PropertyInfo p)
{
return true;
}
我认为它所涉及的部分是这个,即使 IList 是一个 ICollection,以下内容也没有被评估为 true:
if (ExportProperty(property) && collectionProperties(property))
我不确定如何在 VS 2010 中调试 .tt (T4) 文件。
当属性是 IList 时生成的类是:
public System.Collections.Generic.IList`1[[Namespace.Inspection, Entities, Version=1.0.4168.906, Culture=neutral, PublicKeyToken=null]] Inspections
{
get; set;
}
什么时候应该:
public System.Collections.Generic.IList<Namespace.Inspection> Inspections
{
get; set;
}
【问题讨论】:
标签: c# visual-studio-2010 t4 dto