better c# code.

C

chris.millar

Can anyone suggest ways in which to improve this c# code, i dont like the SetXMLSetting and GetXMLSetting methods, could these be put into a property, and how?

Any other ways to make the code more clean and oo.?

cheers

using System;
using System.Configuration;
using System.Xml;

namespace test
{
/// <summary>
/// Summary description for ConsoleExtraction.
/// </summary>
class ConsoleExtraction
{
private static string m_LastExportedDate;

public static string LastExportedDate
{
set
{
m_LastExportedDate = LastExportedDate;
}
get
{
return m_LastExportedDate;
}
}

/// <summary>
/// The main entry point Extraction Application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
m_LastExportedDate = GetXMLSetting("LastExportedDate");
Extract ext = new Extract();
ext.ExtractToTempTables();
SetXMLSetting();
}

static string GetXMLSetting(string exDate)
{
XmlDocument settingDoc = new XmlDocument();
settingDoc.Load(AppDomain.CurrentDomain.BaseDirectory + "\\Settings.xml");
XmlNode setting;

setting = settingDoc.SelectSingleNode("/Settings/LastExportedDate",null);

return setting.InnerXml.ToString();

}

static void SetXMLSetting()
{
XmlDocument settingDoc = new XmlDocument();
settingDoc.Load(AppDomain.CurrentDomain.BaseDirectory + "\\Settings.xml");
XmlNode setting;

setting = settingDoc.SelectSingleNode("/Settings/LastExportedDate",null);

setting.InnerXml = System.DateTime.Now.ToString();

settingDoc.Save(AppDomain.CurrentDomain.BaseDirectory + "\\Settings.xml");

}
}
}


**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
S

Saradhi

you write your own class with properties and use these funtions inside that class and finally use the class in your code.
Can anyone suggest ways in which to improve this c# code, i dont like the SetXMLSetting and GetXMLSetting methods, could these be put into a property, and how?

Any other ways to make the code more clean and oo.?

cheers

using System;
using System.Configuration;
using System.Xml;

namespace test
{
/// <summary>
/// Summary description for ConsoleExtraction.
/// </summary>
class ConsoleExtraction
{
private static string m_LastExportedDate;

public static string LastExportedDate
{
set
{
m_LastExportedDate = LastExportedDate;
}
get
{
return m_LastExportedDate;
}
}

/// <summary>
/// The main entry point Extraction Application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
m_LastExportedDate = GetXMLSetting("LastExportedDate");
Extract ext = new Extract();
ext.ExtractToTempTables();
SetXMLSetting();
}

static string GetXMLSetting(string exDate)
{
XmlDocument settingDoc = new XmlDocument();
settingDoc.Load(AppDomain.CurrentDomain.BaseDirectory + "\\Settings.xml");
XmlNode setting;

setting = settingDoc.SelectSingleNode("/Settings/LastExportedDate",null);

return setting.InnerXml.ToString();

}

static void SetXMLSetting()
{
XmlDocument settingDoc = new XmlDocument();
settingDoc.Load(AppDomain.CurrentDomain.BaseDirectory + "\\Settings.xml");
XmlNode setting;

setting = settingDoc.SelectSingleNode("/Settings/LastExportedDate",null);

setting.InnerXml = System.DateTime.Now.ToString();

settingDoc.Save(AppDomain.CurrentDomain.BaseDirectory + "\\Settings.xml");

}
}
}


**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top