#region Author //// Yevhen Bobrov, http://blog.xtalion.com #endregion using System; using System.Collections.Generic; using System.Reflection; using System.Reflection.Emit; namespace Sample.Silverlight.WCF.Infrastructure.Services { public class AsyncServiceInterfaceFactory { static readonly Lazy<AsyncServiceInterfaceFactory> singleton = new Lazy<AsyncServiceInterfaceFactory>(() => new AsyncServiceInterfaceFactory(), true); public static AsyncServiceInterfaceFactory Instance { get { return singleton.Value; } } readonly ModuleBuilder module; readonly Dictionary<Type, Type> generated = new Dictionary<Type, Type>(); public AsyncServiceInterfaceFactory() { var assemblyName = new AssemblyName("Silverlight.WCF.AutoGeneratedAsyncInterfaces"); AppDomain appDomain = AppDomain.CurrentDomain; AssemblyBuilder assemblyBuilder = appDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); module = assemblyBuilder.DefineDynamicModule("Silverlight.WCF.AutoGeneratedAsyncInterfaces.dll"); } public Type Generate(Type syncInterface) { lock (generated) { if (!generated.ContainsKey(syncInterface)) generated[syncInterface] = GenerateAsyncInterface(syncInterface); return generated[syncInterface]; } } Type GenerateAsyncInterface(Type syncInterface) { var generator = new AsyncServiceInterfaceGenerator(module, syncInterface); return generator.Generate(); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The MIT License