I have an instance of a unknown object and I am iterating through it's properties, I must retrieve each instance of each property, currently this is my solution:
private static void WriteMembers(object arg, XmlWriter writer, object[] attributes)
{
foreach (var property in arg.GetType().GetProperties())
{
if (attributes.All(x => x.GetType() != typeof (XmlIgnoreAttribute)))
{
if (property.GetIndexParameters().Length > 0)
{
//how to get list reference?
}
else
{
var value = property.GetValue(arg, null);
if (value != null)
{
WriteMember(value, property.Name, writer, property.GetCustomAttributes(false));
}
}
}
}
}
But I can't use PropertyInfo.GetValue
to get the list reference because it throws TargetParameterCountException
since the list has an indexed property.
How can I retrieve the list instance?
Aucun commentaire:
Enregistrer un commentaire