5,530,111 members and growing! (14,946 online)
Email Password   helpLost your password?
Languages » XML » XML/XSLT     Intermediate

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

By A.Raja Sekhar

Genaration of GET/SET methods using XML and XSLT.
C#, XML, Windows, .NET, Visual Studio, Dev

Posted: 25 Nov 2004
Updated: 25 Nov 2004
Views: 32,081
Bookmarked: 4 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
9 votes for this Article.
Popularity: 2.54 Rating: 2.67 out of 5
5 votes, 55.6%
1
2 votes, 22.2%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
2 votes, 22.2%
5

Sample Image

Introduction

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.

Background

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:

<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;
    }
}

Points of Interest

I learnt XML and XSLT.

License

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

A.Raja Sekhar



Location: India India

Other popular XML articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralExtension of above Tool.memberRaja Sekhar Amirapu21:18 29 Nov '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin 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-2008
Web12 | Advertise on the Code Project