Skip to content

Instantly share code, notes, and snippets.

@ytez
Created August 23, 2021 01:38
Show Gist options
  • Select an option

  • Save ytez/3bd5acd2b87e7e7e79868ddf27c3b0be to your computer and use it in GitHub Desktop.

Select an option

Save ytez/3bd5acd2b87e7e7e79868ddf27c3b0be to your computer and use it in GitHub Desktop.
[PowerShell] C# コードの実行
@echo off
PowerShell -NoProfile -ExecutionPolicy RemoteSigned -File %~dpn0.ps1
rem pause
# 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