Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Create property from field by right click

2.50/5 (3 votes)
22 Sep 2013CPOL 9.5K  
Get/set property by right clicking on .NET IDE.

Introduction 

This will help developer to create property by setting the field name and datatype .

Background 

This article will help developer to generate property by right click on field.

Using the code

C#
public class Student  
{ 
   string Username; 
   public string _Username
   {
       get { return Username; }
       set { Username = value; }
   }  
}

Above student class has a field called Username and we have set the property for them. Now in .NET instead of write these code we can generated by right click on field name .

Create a class and field then right click on field.   click on Refactor then Encapsulated Field as show in the image.

Image 1

Following window will popup. 

Image 2

Type the property name in property text box and click on ok

 Following will be generated by .net IDE. 

C#
public string Username1
{ 
  get { return Username; }
  set { Username = value; } 
}

Points of Interest

This option is really helpful for auto generating properties by creating the field type and setting the datatype.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)