Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Thursday, September 14, 2006

.NET Code for Pluck Function

Description: Inspired by the javascript prototype library, this method grabs a value of property off of each element contained within a collection and returns an array containing elements of the same type as the property.

public Array Pluck(string propertyName){	
Type type = typeof(Person);	PropertyInfo property = 
Array result = Array.CreateInstance(property.PropertyType, 
for(int i=0;i<this.Count;i++){		
BindingFlags.GetProperty, null, this[i], null), i);
return result;}

Post a Comment