Skip to content

Instantly share code, notes, and snippets.

@kazuk
Created April 14, 2012 02:18
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 kazuk/2381607 to your computer and use it in GitHub Desktop.
Save kazuk/2381607 to your computer and use it in GitHub Desktop.
ASP.NET HttpApplication からすべての Event key object を取得する
<#@ 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