Cutting down repeating code in c# Class

Posted by Tom Gullen on Stack Overflow See other posts from Stack Overflow or by Tom Gullen
Published on 2011-03-18T23:57:25Z Indexed on 2011/03/19 0:10 UTC
Read the original article Hit count: 150

Filed under:
|
|
|
|

This is a wrapper for an API I'm working on, am I doing it sort of right? I'm not particularly fond of all the repeating code in the constructor, if someone can show me if I can reduce that it would be very helpful!

public class WebWizForumVersion
{
    // Properties of returned data
    public string Software { get; private set; }
    public string Version { get; private set; }
    public string APIVersion { get; private set; }
    public string Copyright { get; private set; }
    public string BoardName { get; private set; }
    public string URL { get; private set; }
    public string Email { get; private set; }
    public string Database { get; private set; }
    public string InstallationID { get; private set; }
    public bool NewsPad { get; private set; }
    public string NewsPadURL { get; private set; }

    public WebWizForumVersion(XmlReader Data)
    {
        try
        {
            Data.ReadToFollowing("Software");
            this.Software = Data.ReadElementContentAsString();
            Data.ReadToFollowing("Version");
            this.Version = Data.ReadElementContentAsString();
            Data.ReadToFollowing("ApiVersion");
            this.APIVersion = Data.ReadElementContentAsString();
            Data.ReadToFollowing("Copyright");
            this.Copyright = Data.ReadElementContentAsString();
            Data.ReadToFollowing("BoardName");
            this.BoardName = Data.ReadElementContentAsString();
            Data.ReadToFollowing("URL");
            this.URL = Data.ReadElementContentAsString();
            Data.ReadToFollowing("Email");
            this.Email = Data.ReadElementContentAsString();
            Data.ReadToFollowing("Database");
            this.Database = Data.ReadElementContentAsString();
            Data.ReadToFollowing("InstallID");
            this.InstallationID = Data.ReadElementContentAsString();
            Data.ReadToFollowing("NewsPad");
            this.NewsPad = bool.Parse(Data.ReadElementContentAsString());
            Data.ReadToFollowing("NewsPadURL");
            this.NewsPadURL = Data.ReadElementContentAsString();
        }
        catch (Exception e)
        {

        }
    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about class