public
Created

  • Download Gist
gistfile1.cs
C#
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
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 types = 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).ToList();;
var sw = Stopwatch.StartNew();
foreach (var type in types)
{
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();
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.