Language: C#
Using Lambda instead Activator.CreateInstance
// usage: // var constructor = GetConstructor<Foo>(); // IFoo foo = constructor(); private static Func<T> GetConstructor<T>() where T : class, new() { ConstructorInfo constructorInfo = typeof(T).GetConstructor(new Type[0]); return Expression.Lambda<Func<T>>(Expression.New(constructorInfo)) .Compile(); }
Tags:
Description:
This code shows how to use Lambda to inistiate new types
copied from : http://www.smelser.net/blog/post/2010/03/05/When-Activator-is-just-to-slow.aspx
copied from : http://www.smelser.net/blog/post/2010/03/05/When-Activator-is-just-to-slow.aspx
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

