-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFluentInterface.tt
More file actions
66 lines (57 loc) · 2.32 KB
/
FluentInterface.tt
File metadata and controls
66 lines (57 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="System.Reflection.Emit" #>
<#@ import namespace="System.Xml.XPath" #>
<#@ output extension=".autogen.cs" #>
<#
var docFile = File.OpenRead(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.xml");
var doc = new XPathDocument(docFile);
var nav = doc.CreateNavigator();
var methods =
typeof(ILGenerator).GetMethods(BindingFlags.Public | BindingFlags.Instance)
.Where(method => method.Name == "Emit")
.Select(method => new {
Method = method,
FullSignature = string.Join(", ", method.GetParameters().Select(param => param.ParameterType + " " + param.Name)),
NameSignature = string.Join(", ", method.GetParameters().Select(param => param.Name)),
TypeSignature = string.Join(",", method.GetParameters().Select(param => param.ParameterType))
})
.Select(method => new {
method.FullSignature,
method.NameSignature,
Docs = string.Join("\r\n",
nav.SelectSingleNode(@"//doc/members/member[@name=""M:" + method.Method.DeclaringType + "." + method.Method.Name + "(" + method.TypeSignature + @")""]")
.InnerXml
.Split(new [] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries)
.Select(str => str.Trim())
.Select(str => " /// " + str)
)
});
docFile.Dispose(); // Can't use a 'using' block as we need to keep the anonymously-typed methods variable in scope!
#>
using System;
using System.Reflection;
using System.Reflection.Emit;
namespace ILGeneratorExtensions
{
public static partial class FluentInterface
{
#pragma warning disable 1584,1711,1572,1581,1580
<# foreach (var method in methods) { #>
<#= method.Docs #>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
public static ILGenerator FluentEmit(this ILGenerator generator, <#= method.FullSignature #>)
{
generator.Emit(<#= method.NameSignature #>);
return generator;
}
<# } #>
#pragma warning restore 1584,1711,1572,1581,1580
}
}