0

I'd like to specify some command line arguments to a C# application. Meanwhile I want to interpret these arguments in C# "as-is".

For example, the argument may be in the form of:

" "\"" + DateTime.Now.AddDays(-1).ToDate("yyyyMMdd") + "\"" "

so the correct behavior is to explain this argument as "20140203" (with quotes).

Is there a clean way to achieve this?

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
derekhh
  • 5,272
  • 11
  • 40
  • 60
  • So, you want to execute C# code passed to your program as a commandline argument? – Blorgbeard Feb 04 '14 at 20:08
  • 1
    What you need is code compilation and execution at runtime. See [execute c# code at runtime from code file](http://stackoverflow.com/questions/4181668/execute-c-sharp-code-at-runtime-from-code-file) – MarcinJuraszek Feb 04 '14 at 20:09
  • @Blorgbeard It's actually valid C# one-line statements rather than code. So I'm wondering if there's a better option rather than calling CodeDOM. – derekhh Feb 05 '14 at 01:33
  • @MarcinJuraszek It's actually valid C# one-line statements rather than code. So I'm wondering if there's a better option rather than calling CodeDOM. – derekhh Feb 05 '14 at 01:34
  • A one-line statement *is* code.. – Blorgbeard Feb 05 '14 at 01:41
  • @Blorgbeard: Yes, sure, it's still code by definition... – derekhh Feb 05 '14 at 04:25

1 Answers1

0

I'd would create a class library that was in charge of passing the data.

public class Parameters
{
  public string GetArgument()
  {
    // Create the string argument you want to pass.
  }

  public void SetProperties(string argument)
  {
    // parse data into this class's properties
  }

  public DateTime BirthDay { get; set; }
}

Now you can share the class between both applications, and make sure the the set/get are updated in the same way.

Erik Philips
  • 53,428
  • 11
  • 128
  • 150