Is it the right approach to call the constructor for each command line argument using C#

  • Thread starter Thread starter Satyaprakash A
  • Start date Start date
S

Satyaprakash A

Guest
Hi,

My requirement is, I need to load the existing xml file from the given path by passing through command line arguments and need to update the xml file from C# code. First time I am working on the C# project. I have done given requirement but need few clarifications and optimization techniques in my code snippet.


namespace SchemaChange
{
class FragmentUpdate
{
private String fragmentFileRU;
private String fragmentFileES;
private XmlDocument docRU;
private XmlDocument docES;
private String fileRU;
private String fileES;
public FragmentUpdate(String filename)
{
string result = Path.GetFileName(filename);

fileRU =
"PCPE_FRAGMENT_RU.wxs";
fileES =
"PCPE_FRAGMENT_ES.wxs";

if (result == fileRU.Trim())
{
fragmentFileRU = filename;
docRU =
new XmlDocument();
docRU.
Load(fragmentFileRU);
UpdateFragmentRU();
}
else if (result == fileES.Trim())
{
fragmentFileES = filename;
docES =
new XmlDocument();
docES.
Load(fragmentFileES);
UpdateFragmentES();
}
}
static void Main(string[] args)
{
if (!(args.Length == 0))
{
foreach (string arg in args)
{
FragmentUpdate fragmentUpdate = new FragmentUpdate(arg);
}
}
}
}


1. I am passing multiple arguments from the command line. So from the Main() function for each argument I am calling the constructor. Is it the right approach to call the constructor for each command line argument?


  1. From the constructor I am calling the functions (UpdateFragmentRU(); and UpdateFragmentES();). Is it the correct approach or can I call these functions from the Main() function.

  2. Any optimization required in the body of the functions UpdateFragmentRU() and UpdateFragmentES().

  3. Can I combine these two functions and optimize?

Please provide your thoughts and suggestions and help my beginning in C#.

Continue reading...
 
Back
Top