Guest User

Untitled

a guest
Apr 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace DP_perf_1
  5. {
  6. using System.Data;
  7. using System.Diagnostics;
  8. using System.ServiceModel;
  9. using System.Web;
  10. using System.Windows;
  11. using System.Windows.Forms;
  12. using System.Xml;
  13.  
  14. using Castle.DynamicProxy;
  15.  
  16. class Program
  17. {
  18. static void Main(string[] args)
  19. {
  20. var generator = new ProxyGenerator(new PersistentProxyBuilder());
  21. int i = 0;
  22. var sw = Stopwatch.StartNew();
  23. foreach (var type in typeof(object).Assembly.GetTypes()
  24. .Union(typeof(Uri).Assembly.GetTypes()
  25. .Union(typeof(DataSet).Assembly.GetTypes())
  26. .Union(typeof(Form).Assembly.GetTypes())
  27. .Union(typeof(AspNetHostingPermission).Assembly.GetTypes()
  28. .Union(typeof(IHasXmlNode).Assembly.GetTypes())
  29. .Union(typeof(ICommunicationObject).Assembly.GetTypes())
  30. .Union(typeof(DependencyPropertyHelper).Assembly.GetTypes())))
  31. .Where(t => t.IsVisible && t.IsInterface && !t.IsGenericTypeDefinition))
  32. {
  33. var target = generator.CreateInterfaceProxyWithoutTarget(type);
  34. i++;
  35. target.GetType();
  36. }
  37.  
  38. sw.Stop();
  39. Console.WriteLine("Number of types proxied: {0}", i);
  40. Console.WriteLine("Time taken {0}",sw.Elapsed);
  41. Console.WriteLine("Total number of generated types {0}",
  42. generator.ProxyBuilder.ModuleScope.ObtainDynamicModuleWithStrongName().GetTypes().Length);
  43. Console.ReadKey(true);
  44. generator.ProxyBuilder.ModuleScope.SaveAssembly();
  45. }
  46. }
  47. }
Add Comment
Please, Sign In to add comment