Created
August 23, 2021 01:38
-
-
Save ytez/3bd5acd2b87e7e7e79868ddf27c3b0be to your computer and use it in GitHub Desktop.
[PowerShell] C# コードの実行
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| PowerShell -NoProfile -ExecutionPolicy RemoteSigned -File %~dpn0.ps1 | |
| rem pause |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://qiita.com/Kosen-amai/items/d68b9590c9e8e8b06377 | |
| $src = @' | |
| using System; | |
| using System.Linq; | |
| public static class TestClass | |
| { | |
| public static void TestMethod() | |
| { | |
| var data = new[] | |
| { | |
| new {id = 1, name = "taro"}, | |
| new {id = 2, name = "jiro"}, | |
| new {id = 3, name = "saburo"}, | |
| }; | |
| var query = | |
| from x in data | |
| where x.id < 3 | |
| select x.name; | |
| foreach(var n in query) | |
| { | |
| Console.WriteLine(n); | |
| } | |
| } | |
| } | |
| '@ | |
| Add-Type -TypeDefinition $src -Language CSharp | |
| [TestClass]::TestMethod() # taroとjiroが出力される |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment