Click here to Skip to main content
14,304,886 members

Generating Get/Set Methods for your C# Code Using XML/XSLT

Rate this:
2.67 (9 votes)
Please Sign up or sign in to vote.
2.67 (9 votes)
24 Nov 2004
Genaration of GET/SET methods using XML and XSLT.

Sample Image


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.

Using the code

Step 1

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).

Step 2

Apply XSL to above generated XML.

Your XML file:

    <Name datatype="int " suffix="int ">EmpCode</Name>
    <Name datatype="string " suffix="str ">EmpName</Name>

Apply XSLT to the above XML. The following code will be generated:

public int EmpCode
        return _intEmpCode;
        _intEmpCode = value;
public string EmpName
        return _strEmpName;
        _strEmpName = value;

Points of Interest

I learnt XML and XSLT.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

No Biography provided

Comments and Discussions

GeneralExtension of above Tool. Pin
Raja Sekhar Amirapu29-Nov-04 20:18
memberRaja Sekhar Amirapu29-Nov-04 20:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 24 Nov 2004


8 bookmarked