Randoom a Michael Friis production

Posted
1 August 2007 @ 12pm

Categories
C#, LINQ

You're reading Randoom, a Michael Friis production

Concise code

Yesterday when porting LinqtoCRM to VS 2008 Beta 2, I had to get an array of the types of the properties of some generic type. This array would be passed to Type.GetConstructor(). I had an array of PropertyInfos which contain the type of the property, and I could have new’ed up an array and looped the types into that. Instead I did this:

PropertyInfo[] props = typeof(T).GetProperties();
Type[] types = props.Select(p => p.PropertyType).ToArray();
ConstructorInfo cInf = typeof(T).GetConstructor(types);


1 Comment

Posted by
Kristian Dupont
1 August 2007 @ 12pm

C# 3.0 is going to be the coolest language ever that has commercial success.
Congrats on your blog – I’m looking forward to frequent enlightenment :)


Leave a Comment