Skip to content

Instantly share code, notes, and snippets.

@kkozmic
Created November 15, 2009 15:45
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 kkozmic/235285 to your computer and use it in GitHub Desktop.
Save kkozmic/235285 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
namespace DP_perf_1
{
using System.Data;
using System.Diagnostics;
using System.ServiceModel;
using System.Web;
using System.Windows;
using System.Windows.Forms;
using System.Xml;
using Castle.DynamicProxy;
class Program
{
static void Main(string[] args)
{
var generator = new ProxyGenerator(new PersistentProxyBuilder());
int i = 0;
var sw = Stopwatch.StartNew();
foreach (var type in typeof(object).Assembly.GetTypes()
.Union(typeof(Uri).Assembly.GetTypes()
.Union(typeof(DataSet).Assembly.GetTypes())
.Union(typeof(Form).Assembly.GetTypes())
.Union(typeof(AspNetHostingPermission).Assembly.GetTypes()
.Union(typeof(IHasXmlNode).Assembly.GetTypes())
.Union(typeof(ICommunicationObject).Assembly.GetTypes())
.Union(typeof(DependencyPropertyHelper).Assembly.GetTypes())))
.Where(t => t.IsVisible && t.IsInterface && !t.IsGenericTypeDefinition))
{
var target = generator.CreateInterfaceProxyWithoutTarget(type);
i++;
target.GetType();
}
sw.Stop();
Console.WriteLine("Number of types proxied: {0}", i);
Console.WriteLine("Time taken {0}",sw.Elapsed);
Console.WriteLine("Total number of generated types {0}",
generator.ProxyBuilder.ModuleScope.ObtainDynamicModuleWithStrongName().GetTypes().Length);
Console.ReadKey(true);
generator.ProxyBuilder.ModuleScope.SaveAssembly();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment