Field encapsulation

Hello,

I would like to present my need of field encapsulation.For example, I have
few fields. I would like to:
1)select them all and encapsulate all fields in one moment
2)have properties placed below all fields
3)have attributes on properties with fields names

private int a;
private int b;
private int c;

[Attribute option="a"]
public int A
{
    get { return a; }
    set { a = value; }
}

[Attribute option="b"]
public int B
{
    get { return b; }
    set { b = value; }
}

[Attribute option="c"]
public int C
{
    get { return c; }
    set { c = value; }
}


If it was possible, it would be also nice to have it grouped into regions
like:

#region Fields
...
#endregion

#region Properties
...
#endregion

#region Methods
...
#endregion


Tell me please is it possible and if so, how to do it.
Thank you very much for help and best wishes.


2 comments
Comment actions Permalink

Hello Milosz
     In order to incapsulate multiple fields at a time, use ReSharper > Edit > Generate Code > Properties (Read-only properties). This will sove 1) and 2) for you. I'm afraid there's no way to automatically mark properties with attributes during encapsulation.
     In order to embrace properties and fields with regions, run ReSharper > Tools > Cleanup Code with 'Full cleanup' profile (or with a custom profile with 'Reorder members' feature turned on).

Andrey Serebryansky

Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"
0
Comment actions Permalink

I have discovered default Encapsulate Field method in Visual Studio is a
snippet kept in C:\Program Files\Microsoft Visual Studio
9.0\VC#\Snippets\1033\Refactoring\  .Does R# also use snippet and if so,
perhaps could I add my attribute to xml code of this snippet?


Milosz Kukla IT Specialist IT Department Autoryzowany Dealer NISSAN A. i R.
Polody Spó³ka Jawna ul. Tymienieckiego 38 60-681 Poznañ Poland Phone: +48
(061) 82 55 089 Mobile: +48 518 312 971 Fax: +48 (061) 82 55 101 Email:
m.kukla@polody.pl
U¿ytkownik "Andrey Serebryansky" <no_reply@jetbrains.com> napisa³ w
wiadomo¶ci
news:28439556.91601271757827010.JavaMail.clearspace@app8.labs.intellij.net...

Hello Milosz
In order to incapsulate multiple fields at a time, use ReSharper > Edit >
Generate Code > Properties (Read-only properties). This will sove 1) and
2) for you. I'm afraid there's no way to automatically mark properties
with attributes during encapsulation.
In order to embrace properties and fields with regions, run ReSharper >
Tools > Cleanup Code with 'Full cleanup' profile (or with a custom profile
with 'Reorder members' feature turned on).

>

Andrey Serebryansky
Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>

---
Original message URL:
http://www.jetbrains.net/devnet/message/5261260#5261260



0

Please sign in to leave a comment.