Breakpoint on enum creation
I have an enum, and I am trying to figure out what code is actually creating an instance of it. I have a whole lot of code, and I am fairly certain the code that I am looking for is in one of the many obscure projects that is not in my current solution, so find usages won't work.
I know there is no such thing as a constructor on an enum, but I would really like a way to break execution and examine the call stack anytime any code creates and uses this enum. I have tried putting breakpoints on individual enum values, but they never toggle, even when I know they 开发者_如何学Pythonare being used.
Is this possible, or am I going to need to take a different route to find what I am looking for.
Well, it is technically possible, assuming you control the code of the enum itself:
- Rename YourEnum to YourEnumInternal
- Create class YourEnum and put a Property for each value in YourEnumInternal, with the same name, and return the respective member of YourEnumInternal.
- Put breakpoints in every property.
Also, if what you really want to do is look at the callstacks when members of this enum are added to a particular collection (as you said in a comment), why not find usages on the collection (which hopefuly has a smaller scope?) and put breakpoints (or better yet, TracePoints with the $CALLSTACK psuedovariable) wherever items are added to it?
You can use Find All References
, then you can set breakpoints in the appropriate places.
You can use the Object Browser in VS to search for your enum. It includes assemblies that are referenced (but not part of your solution as projects).
精彩评论