How can we help you today? How can we help you today?

Enable "Analyze" function for enum members

A function I often missed in .NET Reflector is to find the usages of a single enumeration member.

E.g. go to type System.Windows.Forms.ComboBoxStyle in Browser pane.
Invoke Analyze on the whole type and open the Used By node in Analyzer pane.
There are a lot of uses of the enum, e.g. System.Windows.Forms.ComboBox.OnResize uses ComboBoxStyle.Simple.
Go back to the System.Windows.Forms.ComboBoxStyle type in Browser pane.
Invoke Analyze on the ComboBoxStyle.Simple member and open the Used By node in Analyzer pane.
The Used By node is empty but should show at least System.Windows.Forms.ComboBox.OnResize, or?
RolandSchneider
0

Comments

3 comments

  • James Moore
    Hi Ronald,

    Thanks for the suggestion. There is a slight ambiguity which worries me about analyzing a single member - if you have a look at System.Windows.Forms.ComboBox.ComboBoxStyle.GetDropdownStyle(); There is a cast in there from an int to a comboboxstyle - it theory this uses every part of the enum although ComboBoxStyle.DropDown is the only one mentioned explicitly in there - would you expect this to be a use of ComboBoxSyle.Simple?

    Thanks,

    James
    James Moore
    0
  • RolandSchneider
    The intention for the requsted analyse method is to find places where specifically one single member (e.g. ComboBoxStyle.Simple) is used and *not* the other members.
    Places where all enum members could potentially be used are already sufficiently covered through the analyse method on the enum type.

    A small test program shows that even source code like
    private static ComboBoxStyle Foo()
    {
        const int value = 1;
        return (ComboBoxStyle)value;
    }
    
    is already disassembled as
    private static ComboBoxStyle Foo()
    {
        return ComboBoxStyle.DropDown;
    }
    
    RolandSchneider
    0
  • Peter Ritchie
    The problem is that enum members aren't really used. They're compiled to integers in code. For example, with this enum:
    public enum MyEnum{
    Zero, One, Two
    }

    to assign MyEnum.Two to an MyEnum local variable the following IL is generated:

    ldc.i4.2

    This doesn't give reflector a specific identifier to search for, it would have to search either for all uses of MyEnum then see if 2 is assigned to it, or vice versa. Obviously this would be very slow.
    Peter Ritchie
    0

Add comment

Please sign in to leave a comment.