473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Tool to generate properties from private fiels

Anyone know a free vs.net 2003 plugin that is capable of generating
properties from private fields for C#? Thanks ahead.

Jan 16 '06 #1
3 1389
Thanks a lot.

Jan 16 '06 #3
Truong Hong Thi wrote:
Anyone know a free vs.net 2003 plugin that is capable of generating
properties from private fields for C#? Thanks ahead.


Use my macro below and bind it to a keycombi, e.g cntrl-shift + n

say you have the field:
private string _foo;

you then type:
string foo

and on that line hit cntrl-shift-n

and you'll get
<summary>Gets / Sets Foo</summary>
public string Foo
{
get { return _foo;}
set { _foo = value;}
}
''' Creates a property.
''' format: type name has to be present at the current line.
''' Uses caMel casing.
Sub CreateProperty()
Dim typeName, propertyName, memberName, nameRead As String
Dim ts As TextSelection
Dim sb As New StringBuilder
Dim boolIsOpened As Boolean

Try
ts = DTE.ActiveDocument.Selection
If (ts.IsEmpty) Then
ts.SelectLine()
End If

typeName = (ts.Text.Split(" ")(0)).Trim()
nameRead = ((ts.Text.Split(" ")(1))).Trim()
propertyName = nameRead.Substring(0, 1).ToUpper &
nameRead.Substring(1)
memberName = "_" + nameRead.Substring(0, 1).ToLower() &
nameRead.Substring(1)

' actual property
sb.Append("/// <summary>" & Environment.NewLine)
sb.AppendFormat("/// Gets / sets {0}{1}", nameRead,
Environment.NewLine)
sb.Append("/// </summary>" & Environment.NewLine)
sb.Append("public " + typeName + " " + propertyName)
sb.Append(vbCrLf)
sb.Append("{")
sb.Append(vbCrLf)

' get
sb.Append("get")
sb.Append(vbCrLf)
sb.Append("{")
sb.Append(vbCrLf)
sb.AppendFormat("return {0};", memberName)
sb.Append(vbCrLf)
sb.Append("}")
sb.Append(vbCrLf)

' set
sb.Append("set")
sb.Append(vbCrLf)
sb.Append("{")
sb.Append(vbCrLf)
sb.AppendFormat("{0} = value;", memberName)
sb.Append(vbCrLf)
sb.Append("}")
sb.Append(vbCrLf)
sb.Append("}")
sb.Append(vbCrLf)
sb.Append(vbCrLf)

'Check to see if UndoContext object is already open.
If DTE.UndoContext.IsOpen = False Then
'Open the UndoContext object to track changes.
Call DTE.UndoContext.Open("CreateProperty " &
propertyName, False)
boolIsOpened = True
End If

' Replace the text
ts.Delete()
ts.Insert(sb.ToString(),
vsInsertFlags.vsInsertFlagsInsertAtStart)
Finally

'If UndoContext was already open, don't close it.
If boolIsOpened = True Then
'Close the UndoContext object to commit the changes.
DTE.UndoContext.Close()
' Format the Selection
ts.SmartFormat()
ts.MoveToPoint(ts.BottomPoint.CreateEditPoint())
ts.LineUp()
End If
End Try
End Sub

Frans
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Jan 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: P Jones | last post by:
Hi, I support an enterprise web application (IE client) built in VB6, with about 200 classes, serving about 7000 users, running on 3 clustered servers. I need to incorporate web reporting for...
26
by: temp | last post by:
Hi, My boss is asking me to generate a column mapping report of all the queries. Basically, we get our data from ORACLE. There's a queary that create new table from ORACLE tables. Then, there...
8
by: Bill Rust | last post by:
I've created an "Add Item" wizard for VB.NET 2003 that allows a user to add a specialized class that works with my application framework. In the wizard, the user can select the interfaces they...
7
by: George Jordanov Ivanov | last post by:
Folks, I have to design the WSDL files of a bunch of XML Web Services. But, unfortunately, I am not very keen on writing the WSDL file line by line, and moreover be aware of the whole standard...
0
by: Richard Gregory | last post by:
Hi, I have the wsdl below, for an Axis web service, and when I select Add Web Refernce in Visual Studio the proxy is missing a class representing the returnedElementsType (see reference.cs below...
4
by: Anastasios Hatzis | last post by:
I'm looking for a pattern where different client implementations can use the same commands of some fictive tool ("foo") by accessing some kind of API. Actually I have the need for such pattern for...
3
by: Anibal Caixinha | last post by:
Hello, I'm trying to create a task manager , for accounting firm, they have a series of regular tasks they need to be able to control , research old records,etc... The problem is that all of these...
2
by: vips | last post by:
I am trying to generate a proxy class from a WSDL contract file that has nested levels of elements/attribute groups. It seems the WSDL.exe tool only reads upto a certain nesting level and then it...
7
by: =?Utf-8?B?TXJOb2JvZHk=?= | last post by:
I am used to using Java's Eclipse IDE where I can choose one or more fields and have the IDE automatically generate getter and setter methods for it. Is there something in the Visual Studio IDE...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.