Friday, December 18, 2015

Code Refactors: Create Properties From Fields

Its feature is pretty self-explanatory, creating properties from class fields.

If something like the following is written somewhere,

 class CodeTester_Fields_ToProperties { private string name; internal double i; public static int HelloWorld; public DateTime HowAreYouMyFriends; }

        all the four fields selected, and the Create Properties From Fields command is called up, the properties will be created accordingly:

class CodeTester_Fields_ToProperties_After
{
private string _name;

public string name
{
get
{
return _name;
}
set
{
value = _name;
}
}

internal double _i;

public double i
{
get
{
return _i;
}
set
{
value = _i;
}
}

public static int _HelloWorld;

public int HelloWorld
{
get
{
return _HelloWorld;
}
set
{
value = _HelloWorld;
}
}

public DateTime _HowAreYouMyFriends;

public System.DateTime HowAreYouMyFriends
{
get
{
return _HowAreYouMyFriends;
}
set
{
value = _HowAreYouMyFriends;
}
}
}

Enjoy!

No comments:

Post a Comment