By Karl Prosser on
1/16/2010 8:27 PM
Have you ever just wanted to run a line or two of C# from within PowerShell and consume the resulting objects from PowerShell? Before V2 you had to do some codedom yourself Plus write a full dotnet class yourself. With V2 you can just do add-type but still you have to write a full class just to run an expression. Anyway how about a year ago after getting fed up with doing that, and also after seeing Mono's C# commandline interface i thought lets do something quick and dirty that could do this.. with the script that will follow you can do stuff like (c being an alias for the function that compiles and runs a C# expression
(c DateTime.Now).adddays(5)
(c "new{a=1,b=2,c=3}").b
c 'from x in Directory.GetFiles(@"f:\downloads") where x.Contains("win") select x'
an interesting thing i found out, was that with the C# compiler in memory i can't create more than one anonymous type (2nd