0

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?

3
  • Normally you'd just use .. But your example doesn't make sense. How would you call an IBar method on an IFoo? Commented Aug 29, 2012 at 23:46
  • @CodesInChaos, my example may not make sense but I think my ask is clear. I can write a Main() wrapper to instantiate a Bar instance, or these methods can be static, not on an interface. I guess the core of my question is what is the tooling to pipeline .NET runtime input/output. Commented Aug 29, 2012 at 23:50
  • @MitchWheat, I'm not familiar with PS, is it easy to adapt existing C# library methods into PS cmdlets? Commented Aug 29, 2012 at 23:52

3 Answers 3

2

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:

$ping = New-Object System.Net.NetworkInformation.Ping
$ping.send("localhost")

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

Sign up to request clarification or add additional context in comments.

Comments

1

One good option is C# Script

http://www.csscript.net/

That allows you to call any .NET assembly from a scripting environment, where the language of the scripting environment is C#.

CS-Script is a CLR (Common Language Runtime) based scripting system which uses ECMA-compliant C# as a programming language. CS-Script currently targets Microsoft implementation of CLR (.NET 2.0/3.0/3.5/4.0) with full support on Mono.

Comments

0

You can also use F# for this. You can use pipes and function composition for sequential data processing and it is a .NET language so you can directly reference C# and VB objects. You can use it both in scripts and a REPL prompt, and the interpreter is included in the .NET SDK by default.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.