I am wondering if there is any language feature/library/tools/techniques I could use to call .NET/C# “functions” in a pipeline in a scripting environment? For example, I have
public interface IFoo
{
...
}
public interface IBar
{
IFoo Load(string fileName);
IFoo Replace(string oldValue, string newValue);
void Save(string fileName);
}
Then wrap them in util.exe with proper Main(). Now I want to use them like piped DOS command:
util.exe -load in.txt | util.exe -replace x y | util.exe -save output.txt
Is it possible? Is there any constraint on IFoo because it can be complex data structure that can’t be easily serialized to ASCII string. What’s the way to get there?
PowerShell is very good option.
First of all you can call any compiled code directly, so if you don’t want to make actual cmdlets in C# you can write calling code in PowerShell and use all its pipeline plumbing to pass data between steps.
I.e. calling Ping.Send:
You can also implement CmdLets for nice PowerShell code and greater control – sample http://www.codeproject.com/Articles/32999/How-to-Write-a-Custom-PowerShell-Cmdlet-Part-I