0

I have a Bank Object that has several nested objects/properties/methods as well as wrapping around a com object. There is limited documentation to this lib and I want to change the Banking Number in the Object but I have no idea what property's name is, or how far down in the object tree. However I do know the value of the property is 1231241. How can I search a object for that value to find it and change it ?

I have tried:

  • digging through the watch window, but the object is huge
  • Bug Aid this is still in beta and it stopped working
  • Object Compare but this didn't work well I think because of the com object

I might just have to get my hands dirty and dig through the watch window but I thought I would see if anyone has any ideas. I am looking for a utility to do this with.

Micah Armantrout
  • 6,781
  • 4
  • 40
  • 66
  • What about using `Reflection`? Maybe you can itare through all the propertiers looking those values without the need to know the names. – Erick Petrucelli Mar 11 '12 at 00:33
  • Is there a utility to do that with ? – Micah Armantrout Mar 11 '12 at 00:33
  • 1
    I don't think so, you'll need to write your own code to inspect the object. This thread maybe be helpful: http://stackoverflow.com/questions/5381851/how-to-recursively-iterate-over-properties-of-an-entity – Erick Petrucelli Mar 11 '12 at 00:35
  • I'm the co-creator of BugAid. By "stopped working", do you mean your trial period ran out, or that you experienced some problem with it? Please let us know through our [Contact Page](http://www.bugaidsoftware.com/support/) so we could help fix the problem. Thanks! – Omer Raviv Mar 11 '12 at 08:21
  • I increased the level to dig to 10 and it would only dig to 3. I will let you know through the contact page – Micah Armantrout Mar 11 '12 at 13:26
  • Also is there any log files I can look at to see if BugAid throwing a exception – Micah Armantrout Mar 12 '12 at 01:20
  • @MicahArmantrout Yes, the log files are at %TEMP%\BugAid\Logs, if you have any problems, please send those log files to us at info@bugaidsoftware.com so we could help and figure out what went wrong. Thank you! – Omer Raviv Mar 12 '12 at 13:51
  • @OmerRaviv I sent the logs this morning along with two error reports – Micah Armantrout Mar 12 '12 at 14:14

1 Answers1

1

Here is a sample that I created using Reflection that maybe can help you:

private static void recurseAndFindProperty(Object obj) {
   foreach (PropertyInfo pi in obj.GetType().GetProperties()) {
       if ((pi.PropertyType.IsGenericType && pi.PropertyType.GetGenericTypeDefinition() == typeof(EntityCollection<>))) {
           IEnumerable collection = (IEnumerable)pi.GetValue(obj, null);

           foreach (object val in collection)
               recurseAndFindProperty(val);
       } else {
            if (pi.PropertyType != typeof(Descendant))
                if ((int)pi.GetValue(obj, null) == 1231241)
                    pi.SetValue(obj, 10, null)); // Change the value.
       }
   }
}
Erick Petrucelli
  • 14,386
  • 8
  • 64
  • 84