Is this possible with Visual Studio snippets?

不打扰是莪最后的温柔 提交于 2019-12-01 09:02:34

问题


I use a modified form of TODO comment (SteveC_TODO) that allows me to group my own todos together in the task list.

Yesterday I thought it would be nice to modify the refactoring snippets to add a todo comment to the usual NotImplemented exception. I modified the Method Stub - Body snippet to this

$signature$
{
  //SteveC_TODO: implement $end$$signature$
  throw new $Exception$();
}

but this results in the todo comment having the full method signature. It serves the purpose but I would prefer the comment to only use the name from the method signature and be of the form

//SteveC_TODO: implement CoolMethod

rather than of the form

//SteveC_TODO: implement private void CoolMethod(object o)

Does anyone know of a way that I can do this? I presume that the arguments passed to refactoring snippets are fixed but perhaps there is a way to parse the $signature$ argument to extract just the name. Anyone know if that might be possible?


回答1:


I think you have to modify it to something like

$accessability$ $returntype$ $method$($arguments$) 
{
   //SteveC_TODO: implement $method$
   $end$throw new $Exception$("The method or operation is not implemented.");
}

You have to declare the literals accessability, returntype, method, arguments,...

Have a look here for how to create codesnippets



来源:https://stackoverflow.com/questions/949825/is-this-possible-with-visual-studio-snippets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!