使用ReSharper模板自动添加导入

使用ReSharper模板自动添加导入,resharper,live-templates,Resharper,Live Templates,我正在为ReSharper编写活动模板,这些模板依赖于外部命名空间中定义的类型 有没有办法告诉它“如果需要,添加一个using指令”,这样我就不必在每次使用后手动修复它 /* Template expands to */ var $ListName$ = new List<$Type$>()$END$; /* But sometimes needs to import */ using System.Collections.Generic; /*模板扩展为*/ var$ListN

我正在为ReSharper编写活动模板,这些模板依赖于外部命名空间中定义的类型

有没有办法告诉它“如果需要,添加一个using指令”,这样我就不必在每次使用后手动修复它

/* Template expands to */
var $ListName$ = new List<$Type$>()$END$;

/* But sometimes needs to import */
using System.Collections.Generic;
/*模板扩展为*/
var$ListName$=new List()$END$;
/*但有时需要导入*/
使用System.Collections.Generic;

是的,这是可能的

完全限定类型名称,然后选择“缩短限定引用”


是的,在模板中,使用完全限定的类型名称,例如

var $ListName$ = new System.Collections.Generic.List<$Type$>();
var$ListName$=new System.Collections.Generic.List();

如果您随后选中“缩短限定引用”,则ReSharper将插入文本作为
new List()
并使用System.Collections.Generic自动添加
如果它还不存在。

那么扩展方法所需的using指令呢?@PPC我担心这对扩展方法(中缀调用)不起作用。我还没有测试过它,但也许它可以与新的R#9.1“源代码模板”一起使用。