![]() |
Languages »
XML »
XML/XSLT
Intermediate
Generating Get/Set Methods for your C# Code Using XML/XSLTBy A.Raja SekharGenaration of GET/SET methods using XML and XSLT. |
C#, XML, Windows, .NET, Visual Studio, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

This article helps in generating get/set methods for C# code automatically if the private member variables are provided. Writing code for get/set methods is a time taking job if you have a number of private member variables.
I got this idea because we had 85 fields in a class for which we needed to write get/set methods. Writing the XML and applying the XSL to it saved my time.
Generate an XML file with all private member variables with attributes suffix and datatype, where suffix is a name such as _str or _STR (Naming Convention).
Apply XSL to above generated XML.
Your XML file:
<xmp>
<Names>
<Name datatype="int " suffix="int ">EmpCode</Name>
<Name datatype="string " suffix="str ">EmpName</Name>
</Names>
</XMP>
Apply XSLT to the above XML. The following code will be generated:
public int EmpCode
{
get
{
return _intEmpCode;
}
set
{
_intEmpCode = value;
}
}
public string EmpName
{
get
{
return _strEmpName;
}
set
{
_strEmpName = value;
}
}
I learnt XML and XSLT.
| You must Sign In to use this message board. | ||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 25 Nov 2004 Editor: Smitha Vijayan |
Copyright 2004 by A.Raja Sekhar Everything else Copyright © CodeProject, 1999-2009 Web19 | Advertise on the Code Project |