Anuya
Anuya

Reputation: 8350

Executing Console application from CMD

I have a lot of functions written in c# console application for illustrating different set of codes. Say if i have functions like writeXML(), readXML(), writeText(), ReadText()

My Main() function will open the command prompt and now, Is it possible to go to cmd and execute a particular function, one by one to illustrate and show the output of each ???

Upvotes: 1

Views: 305

Answers (2)

mousio
mousio

Reputation: 10347

Maybe Roslyn for interactive C# is an option?

It even has a scripting API, but I am quite pleased with this standalone Roslyn REPL (and now there is also a more elegant GUI).

Upvotes: 0

Parv Sharma
Parv Sharma

Reputation: 12705

in short the ans is a no..
but yes you can use reflection combined with Console.ReadLine() to do what you wanna do
something like this

while(true)
{
 var cmd = Console.ReadLine();
 var methodInfo = from m in (classObject).GetType().GetMethods() where m.Name == cmd;
 methodInfo.Invoke(classObject, new object[] { /* arguments to method */ });
}

NOTE:-the code i have given here is just a pseudo code and not valid but you will be able to make your way through once you start applying it

Upvotes: 1

Related Questions