I\'m trying to compare two objects at runtime using reflection to loop through their properties using the following method:
for C#
:
PropertyInfo property = .....
ParameterInfo[] ps = property.GetIndexParameters();
if (ps.Count() > 0)
{
if(obj.ToString().Contains("+"))
{
Debug.Write("object is multi-type");
}
else {
var propValue = property.GetValue(obj, null);
....
}
}
This was plenty for me to skip over indexers.
obj.GetType().GetProperties().Where(x => !x.GetIndexParameters().Any())
I suspect your type contains an indexer - i.e. a property which takes parameters. You can check for this by calling PropertyInfo.GetIndexParameters and checking if the returned array is empty.
(If that isn't the problem, please edit your question to show a short but complete program demonstrating the issue.)