是否可以在Visual Studio(2013)类图中配置关联,以便在从中生成代码时创建具有类型List<MyClass>
或甚至ICollection<MyClass>
的属性,而不是默认值IEnumerable<MyClass>
?
是否可以在Visual Studio(2013)类图中配置关联,以便在从中生成代码时创建具有类型List<MyClass>
或甚至ICollection<MyClass>
的属性,而不是默认值IEnumerable<MyClass>
?
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Architecture Tools\Extensibility\Templates\Text
中找到这些模板(如果你的计算机是32位的,则删除(x86))。IList<T>
而不是默认的IEnumerable<T>
:
Locate the method named ElementType(IType type, bool isEnumerable = false)
private static string ElementType(IType type, bool isEnumerable = false)
{
string text = string.Empty;
if (type == null)
{
text = "object";
}
else
{
text = TypeName(type);
}
if(!string.IsNullOrWhiteSpace(text) && isEnumerable)
{
//SO Change IEnumerable to IList here
text = "IEnumerable<" + text + ">";
}
return text;
}
Change the string IEnumerable to whatever you want (see my comment starting with SO)
你甚至可以编写自己的T4模板,并指示Visual Studio在生成代码时使用它们,更多详细信息请参见MSDN。