当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Shortcut to create property associated to a field?

问题描述:

I have to make many combination of field and property. I cannot use the implicit property version "{ get; set; }" since the fields need some attributes.

So, in Visual Studio Express 2013, is there a way to have a shortcut to create a property associated with a field I just ended up writing?

Let's say I write;

private MyType myData;

and I press CTRL+P (whatever the shortcut), and it adds

public MyType MyData

{

get { return myData; }

set { myData = value; }

}

just after.

Is it possible?

EDIT:

The Express version however does only have two refactoring functionalities: rename and extract method, the other functionalities like encapsulate are not present.

I guess I'm stuck.

网友答案:

Check this out: http://msdn.microsoft.com/en-us/library/z41h7fat.aspx

this might also be useful (Create your own snippets) : http://msdn.microsoft.com/en-us/library/vstudio/ms165394.aspx

here you have all the code snippets you need including "prop", which is the one you need now!

Hope it helps

网友答案:

By what you are asking 3 simple clicks will do it like this:

rigth-click in your field then Refactor-->EncapsulateField

And your done.

网友答案:

You should use code snippet and assign hotkey for it.

More information about managing code snippets here: http://msdn.microsoft.com/en-us/library/ms165394.aspx

分享给朋友:
您可能感兴趣的文章:
随机阅读: