Created
September 22, 2010 12:03
-
-
Save kkozmic/591560 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Runtime.CompilerServices; | |
using Castle.DynamicProxy; | |
namespace ConsoleApplication7 | |
{ | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
var generator = new ProxyGenerator(); | |
var exceptions = new HashSet<Type> | |
{ | |
typeof (TypedReference), | |
typeof (ArgIterator), | |
typeof (RuntimeArgumentHandle), | |
typeof (void) | |
}; | |
var types = | |
typeof (object).Assembly.GetExportedTypes() | |
.Where(t => t.IsGenericTypeDefinition == false && exceptions.Contains(t) == false) | |
.ToArray(); | |
Console.WriteLine("Experimenting with {0} types", types.Length); | |
var sw = Stopwatch.StartNew(); | |
for (var i = 0; i < types.Length; i++) | |
{ | |
var type = MakeGenericFoo(types[i]); | |
var instance = Instantiate(type, generator); | |
} | |
Console.WriteLine("Done: {0}", sw.Elapsed); | |
} | |
[MethodImpl(MethodImplOptions.NoInlining)] | |
private static void Invoke(IList instance) | |
{ | |
instance.Clear(); | |
} | |
[MethodImpl(MethodImplOptions.NoInlining)] | |
private static object Instantiate(Type type, ProxyGenerator generator) | |
{ | |
return generator.CreateInterfaceProxyWithoutTarget(type); | |
} | |
[MethodImpl(MethodImplOptions.NoInlining)] | |
private static Type MakeGenericFoo(Type type) | |
{ | |
return typeof (IFoo<>).MakeGenericType(type); | |
} | |
} | |
public interface IFoo<T> | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment