2010-05-13 6 views
0

J'ai un objet propertyInfo et j'essaie de faire un GetValue en l'utilisant.Réflexion PropertyInfo GetValue appelle les erreurs pour la propriété de type Collection <>

object source = mysourceObject //This object has a property "Prop1" of type Collection<>. 

var propInfo = source.GetType().GetProperty("Prop1"); 

var propValue = prop.GetValue(this, null); 

// do whatever with propValue 
// ... 

J'obtiens l'erreur à l'appel GetValue() comme "La valeur ne peut être nulle \ r \ nParameter nom. Source"

"Prop1" est une propriété déclarée plaine Collection.

prop.PropertyType = {Name = "Collection 1" FullName = "System.Collections.ObjectModel.Collection 1 [[Application1.DummyClass, Application1, Version = 1.5.5.5834, Culture = neutral, PublicKeyToken = 628b2ce865838339]]"} {System.Type System.RuntimeType}

Répondre

1

Vous devez obtenir la valeur de la propriété pour source, non this:

var propValue = prop.GetValue(source, null); 
Questions connexes