自动创建 getter/setter 的代码片段?
我曾经使用过我过去看到/发现的一个代码片段,它将我的单个语句变成私有/公共 getter/setter,自从重新安装我的机器以来,我到目前为止无法重复这个发现。
例如:
private string serverSMTP = string.empty;
然后我可以按 Ctrl k + 并将其变成这样:
private string serverSMTP = string.Empty;
public string ServerSMTP
{
get { return serverSMTP; }
set
{
serverSMTP = value;
RaisePropertyChanged("ServerSMTP");
}
}
关于如何创建一些东西来执行此操作或扩展/片段来为我处理它的任何想法?在较大的项目中,这会节省我很多时间。
I once used a code snippet I saw/found in the past that would turn my single statement into a private/public getter/setter, I've been so far unable to repeat that find since reinstalling my machine.
for example:
private string serverSMTP = string.empty;
I could then press Ctrl k + and turn it into this:
private string serverSMTP = string.Empty;
public string ServerSMTP
{
get { return serverSMTP; }
set
{
serverSMTP = value;
RaisePropertyChanged("ServerSMTP");
}
}
Any ideas on how I can create something to do that or an extension/snippet to take care of it for me? In larger projects this would save me a lot of time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您已经在使用 MVVM Light 框架,您可以安装它附带的代码片段来执行类似的操作。具体来说,“mvvminpc”片段将执行您正在寻找的操作,尽管它不会采用现有的字段声明并将其转换为具有 propertychanged 通知的属性。
http://mvvmlight.codeplex.com/sourcecontrol/最新#Installer/InstallItems/Snippets/CSharp/mvvmInpc.snippet
If you are already using the MVVM Light framework you can install the code snippets that ship with it that will do something similar. Specifically the "mvvminpc" snippet will do what you are looking for, although it will not take an existing field declaration and convert it to a property with a propertychanged notification.
http://mvvmlight.codeplex.com/sourcecontrol/latest#Installer/InstallItems/Snippets/CSharp/mvvmInpc.snippet
将此片段放入
以下文件夹中的文件 propn.snippet 中:
C:\Users[YOUR_USERNAME]\Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets
,之后您将能够使用 (propn + tab + tab) 快捷方式使用此代码片段。
xml 片段非常容易您自己理解,因此您可以轻松地将其调整为您需要的任何内容。
put this snippet:
inside a file propn.snippet, in this folder:
C:\Users[YOUR_USERNAME]\Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets
and afterwards you'll be able to use this snippet using the (propn + tab + tab) shortcut.
the snippet xml is very easy to understand on your own, so you can easily adjust it to whatever you need.