Reputation: 78545
Right now I'm looking at a bug in some C# code where I need to get a given object instance at some location. I'm sitting on a breakpoint at that location in the debugger and can jump back up the stack and view the object instance that I need to get. I suspect that there is a way to get that instance from what I have (foo.bar.baz.bla.bla.bla
or something like that) but I'm not knowledgeable enough about the code to know how to find it.
Hypothetical Example:
I'm sitting in the debugger at line 2485 in some one eases code and realize that the program needs to, right here, set the
FooBat
property on the enclosingWizBang
object (the one that the function 27 steps up the call stack was called on) but I don't have any direct references to the enclosingWizBang
object. However I suspect that one of the other object I do have access to has access to something that has access to something that does have access to the enclosingWizBang
object. But that gives me about 10K things to look through and, oh by the way, I can also access 42 differentWizBang
objects that are not the one I want so I also need to check that it really is the same object as the one 27 steps up the stack. If I can just find how to get access to it I can addSomeExp.FooBat = true;
right here on line 2485 and close this bug!
My question is: has anyone made a tool that uses reflection and bruit force to search chains of properties and members to find one that will give a desired object instance?
Yes I know this is an O(b
d
)
problem and often won't work but it's computer time, not programmer time and when it does work, it would be fantastic!
p.s. I give it less than even odd of what I want existing (now <g/>
).
Upvotes: 2
Views: 343
Reputation: 23789
I think what you're after is something that you would have to write yourself. That said, I don't imagine it to be very difficult - after all, you just need to write a method that uses reflection to traverse whatever object structure you're working with, checking for a specific condition. Then, you simply set a breakpoint (or hit Pause) and then run your method on whatever object structure you need. You can probably set the method to [Conditional(DEBUG)]
so it doesn't appear in the release version of your program.
Upvotes: 0
Reputation: 32900
Although reading all your comments and posts I'm not sure whether I correctly understood what you want. Did you try conditional breakpoints in Visual Studio? They may help as well. You can use them to check whether your object fulfills some conditions and just stop in that case.
Upvotes: 0
Reputation: 35741
maybe you should try the "Immediate window" where you can enter c# live. It can evaluate only expressions and assignments (no declarations etc).
You can find the immediate window from Debug->Windows->Immediate (Ctrl-Alt-I by default)
Did you try that already?
Upvotes: 2
Reputation: 4009
Maybe you can use the watch-window of the visual-studio debugger. You could insert your instance once and watch it every step.
Upvotes: 0