Created
April 14, 2012 02:18
-
-
Save kazuk/2381607 to your computer and use it in GitHub Desktop.
ASP.NET HttpApplication からすべての Event key object を取得する
This file contains 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
<#@ template debug="false" hostspecific="false" language="C#" #> | |
<#@ assembly name="System.Core" #> | |
<#@ assembly name="System.Web" #> | |
<#@ output extension="EventKeys.cs" #> | |
<#@ import namespace="System.Web" #> | |
<#@ import namespace="System.Reflection" #> | |
<#@ import namespace="System.Linq" #> | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Web; | |
using System.Reflection; | |
namespace Kazuk.Dark | |
{ | |
public static partial class HttpApplicationExtentions | |
{ | |
<# | |
Type t = typeof(System.Web.HttpApplication); | |
var eventFields= | |
typeof(System.Web.HttpApplication) | |
.GetFields( BindingFlags.NonPublic | BindingFlags.Static ) | |
.Cast<FieldInfo>() | |
.Where( f=>f.Name.StartsWith( "Event", StringComparison.Ordinal ) ); | |
foreach( var field in eventFields ) | |
{ | |
#> | |
public static readonly object <#=field.Name#>; | |
<# | |
} | |
#> | |
public static HttpApplicationExtentions() | |
{ | |
const BindingFlags NonPubStatic | |
= BindingFlags.NonPublic | BindingFlags.Static; | |
Func<Type, string, object> getFieldValue | |
= (t,n ) => | |
t.GetField(n, NonPubStatic) | |
.GetValue(null); | |
Type httpAppType = typeof(HttpApplication); | |
<# | |
foreach( var field in eventFields ) | |
{ | |
#> | |
<#=field.Name#> = | |
getFieldValue( httpAppType, "<#=field.Name#>" ); | |
<# | |
} | |
#> | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment