better c# code.

  • Thread starter Thread starter chris.millar
  • Start date Start date
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...
 
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...
 
Back
Top