Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Created September 19, 2017 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atifaziz/a5fa2a3dbc6e55de55a419b48a637ef9 to your computer and use it in GitHub Desktop.
Save atifaziz/a5fa2a3dbc6e55de55a419b48a637ef9 to your computer and use it in GitHub Desktop.
#r "System.Net.Http"
#r "System.Threading.Tasks"
#r "packages\Microsoft.CodeAnalysis.CSharp.2.3.2\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll"
using System.Net.Http;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
var source = await new HttpClient().GetStringAsync("https://gist.githubusercontent.com/atifaziz/779846996638e50cbf11554c75739178/raw/8e0ef8f52c1beadd5f6a6cbb464737e2bce0f9c9/Enumerable.cs");
var output =
from m in CSharpSyntaxTree.ParseText(source)
.GetRootAsync().GetAwaiter().GetResult()
.DescendantNodes().OfType<MethodDeclarationSyntax>()
select $@" {m.ToString().TrimEnd(';')} =>
LinqEnumerable.{m.Identifier}({string.Join(", ", from p in m.ParameterList.Parameters
select p.Identifier)});";
Console.WriteLine($@"static class Enumerable
{{
{string.Join(Environment.NewLine + Environment.NewLine, output)}
}}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment