2010-05-13 88 views
0

我有一個propertyInfo對象,我試着做一個GetValue使用它。反射PropertyInfo GetValue調用錯誤集合<>類型屬性

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 
// ... 

我在的GetValue()調用中出現錯誤「值不能爲空\ r \ n參數名:源」

「PROP1」被聲明爲收集普通屬性。

prop.PropertyType = {名稱= 「類別1" FullName = "System.Collections.ObjectModel.Collection 1 [[Application1.DummyClass,應用1,版本= 1.5.5.5834文化=中性公鑰= 628b2ce865838339]]」}的System.Type {System.RuntimeType}

回答

1

你需要獲得source屬性值,而不是this

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