@@ -51,42 +51,62 @@ public BaseNumericNode GetUnderlayingNode()
5151 throw new Exception ( ) ; // TODO
5252 }
5353
54- public long ReadValueFromMemory ( MemoryBuffer memory )
54+ private long ReadValueFromMemory ( MemoryBuffer memory )
55+ {
56+ switch ( Enum . Size )
57+ {
58+ case EnumDescription . UnderlyingTypeSize . OneByte :
59+ return memory . ReadInt8 ( Offset ) ;
60+ case EnumDescription . UnderlyingTypeSize . TwoBytes :
61+ return memory . ReadInt16 ( Offset ) ;
62+ case EnumDescription . UnderlyingTypeSize . FourBytes :
63+ return memory . ReadInt32 ( Offset ) ;
64+ case EnumDescription . UnderlyingTypeSize . EightBytes :
65+ return memory . ReadInt64 ( Offset ) ;
66+ }
67+
68+ throw new Exception ( ) ; // TODO
69+ }
70+
71+ private ulong ReadFlagsValueFromMemory ( MemoryBuffer memory )
5572 {
56- switch ( Enum . Size )
57- {
58- case EnumDescription . UnderlyingTypeSize . OneByte :
59- return memory . ReadInt8 ( Offset ) ;
60- case EnumDescription . UnderlyingTypeSize . TwoBytes :
61- return memory . ReadInt16 ( Offset ) ;
62- case EnumDescription . UnderlyingTypeSize . FourBytes :
63- return memory . ReadInt32 ( Offset ) ;
64- case EnumDescription . UnderlyingTypeSize . EightBytes :
65- return memory . ReadInt64 ( Offset ) ;
66- }
67-
68- throw new Exception ( ) ; // TODO
69- }
70-
71- private string GetStringRepresentation ( long value )
73+ // Flags should be read as an unsigned value.
74+ switch ( Enum . Size )
75+ {
76+ case EnumDescription . UnderlyingTypeSize . OneByte :
77+ return memory . ReadUInt8 ( Offset ) ;
78+ case EnumDescription . UnderlyingTypeSize . TwoBytes :
79+ return memory . ReadUInt16 ( Offset ) ;
80+ case EnumDescription . UnderlyingTypeSize . FourBytes :
81+ return memory . ReadUInt32 ( Offset ) ;
82+ case EnumDescription . UnderlyingTypeSize . EightBytes :
83+ return memory . ReadUInt64 ( Offset ) ;
84+ }
85+
86+ throw new Exception ( ) ; // TODO
87+ }
88+
89+ private string GetTextRepresentation ( MemoryBuffer memory )
90+ {
91+ return Enum . UseFlagsMode ? GetFlagsStringRepresentation ( memory ) : GetStringRepresentation ( memory ) ;
92+ }
93+
94+ private string GetStringRepresentation ( MemoryBuffer memory )
7295 {
73- if ( ! Enum . UseFlagsMode )
74- {
96+ var value = ReadValueFromMemory ( memory ) ;
7597 var index = Enum . Values . FindIndex ( kv => kv . Value == value ) ;
7698 if ( index == - 1 )
7799 {
78100 return value . ToString ( ) ;
79101 }
80102
81103 return Enum . Values [ index ] . Key ;
82- }
83-
84- return GetFlagsStringRepresentation ( value ) ;
85104 }
86105
87- private string GetFlagsStringRepresentation ( long value )
88- {
89- var result = ( ulong ) value ;
106+ private string GetFlagsStringRepresentation ( MemoryBuffer memory )
107+ {
108+ var value = ReadFlagsValueFromMemory ( memory ) ;
109+ var result = value ;
90110
91111 var values = Enum . Values ;
92112
@@ -163,9 +183,9 @@ public override Size Draw(ViewInfo view, int x, int y)
163183
164184 x = AddText ( view , x , y , view . Settings . TextColor , HotSpot . NoneId , "=" ) + view . Font . Width ;
165185
166- var value = ReadValueFromMemory ( view . Memory ) ;
186+ var text = GetTextRepresentation ( view . Memory ) ;
167187
168- x = AddText ( view , x , y , view . Settings . TextColor , HotSpot . NoneId , GetStringRepresentation ( value ) ) + view . Font . Width ;
188+ x = AddText ( view , x , y , view . Settings . TextColor , HotSpot . NoneId , text ) + view . Font . Width ;
169189
170190 x = AddComment ( view , x , y ) ;
171191
0 commit comments