对INotifyPropertyChanged使用代码段 [英] using a Code Snippet for INotifyPropertyChanged
本文介绍了对INotifyPropertyChanged使用代码段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找到了INotifyPropertyChanged的代码段
I found this code snippet for INotifyPropertyChanged
但是它显示了这样的代码:
But it shows the code like this :
我会这样的:
-
公开:首字母大写+ ...
for public : capital letter for the first letter + ...
私有:下划线+首字母小写+ ...
for private : underscore + small letter for the first letter + ...
我该如何实现?
无需键入公共字段和私有字段
Edit : Without having to type the public and the private fields
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>string</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal>
<ID>notifyMethod</ID>
<ToolTip>name of method to raise PropertyChanged event</ToolTip>
<Default>NotifyPropertyChanged</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[private $type$ _$property$;
public $type$ $property$
{
get { return _$property$;}
set
{
if (value != _$property$)
{
_$property$ = value;
$notifyMethod$("$property$");
}
}
}
$end$]]>
</Code>
</Snippet>
推荐答案
我认为这不能通过Visual Studio提供的本机代码段功能来完成.
I don't think this can be done with native code snippets feature provided by Visual Studio.
我个人使用Resharper使其成为可能.它可以变成我写的代码
Personally I use Resharper which makes it possible. It can turn code I write like
public string Name { get; set; }
进入
private string _name;
public string Name
{
get { return _name; }
set
{
if(value == _name)
return;
_name = value;
OnPropertyChanged("Name");
}
}
它甚至为您生成OnPropertyChanged()
方法.
这篇关于对INotifyPropertyChanged使用代码段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文