I'm in the process of creating a Binding solution within Mono that enables developers to have two-way binding. All property types work except IEnumerable
, in that for some reason Mono throws an InvalidCastException
whenever I event attempt to try and use PropertyInfo.GetValue()
for it.
Even though the PropertyInfo
shows all signs that the Collection<>
/ IEnumerable<>
is finding its type correctly (ie if I debug, it shows that the property being passed in derives a Collection...but just can't extract the actual value?
Here's the code:
var src = Source.GetType().GetProperty("Foo");
if (typeof (IEnumerable).IsAssignableFrom(SourceProperty.PropertyType))
{
var obj = src.GetValue(Source, null);
}
The error I get:
InvalidCastException: Cannot cast from source type to destination type.
System.Reflection.MonoProperty.GetterAdapterFrame[VMController,Array] (System.Reflection.Getter`2 getter, System.Object obj) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoProperty.cs:234) System.Reflection.MonoProperty.GetValue (System.Object obj, System.Object[] index) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoProperty.cs:292)
Aucun commentaire:
Enregistrer un commentaire