Skip to content

Commit

Permalink
Display enums as string in Linqpad results
Browse files Browse the repository at this point in the history
  • Loading branch information
fbrosseau committed Jul 12, 2016
1 parent a79eb54 commit 36cbcbd
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions ClrMD.Extensions/ClrObject.cs
Expand Up @@ -108,6 +108,16 @@ public object SimpleValue
get { return SimpleValueHelper.GetSimpleValue(this); }
}

public object SimpleDisplayValue
{
get
{
if (Type.IsEnum)
return Type.GetEnumName(SimpleValue) ?? SimpleValue.ToString();
return SimpleValue;
}
}

public ulong Size
{
get { return Type.GetSize(Address); }
Expand Down Expand Up @@ -807,7 +817,7 @@ public IEnumerable<Type> GetTypes()
{
if (HasSimpleValue)
{
yield return GetSimpleValueType();
yield return GetSimpleValueType();
}
else if (IsUndefined())
{
Expand Down Expand Up @@ -864,7 +874,7 @@ public IEnumerable<object> GetValues()
}
else if (!IsNull() && HasSimpleValue)
{
yield return SimpleValue;
yield return SimpleDisplayValue;
}
else if (!IsNull() && Type.IsArray)
{
Expand All @@ -887,7 +897,7 @@ public IEnumerable<object> GetValues()
foreach (ClrInstanceField field in Type.Fields)
{
if (LinqPadExtensions.SmartNavigation)
yield return (!this[field].IsNull() && this[field].HasSimpleValue) ? this[field].SimpleValue : this[field];
yield return (!this[field].IsNull() && this[field].HasSimpleValue) ? this[field].SimpleDisplayValue : this[field];
else
yield return this[field].ToString();
}
Expand All @@ -908,7 +918,11 @@ private IEnumerable<ClrObject> EnumerateArray()

private Type GetSimpleValueType()
{
return SimpleValue == null ? typeof(object) : SimpleValue.GetType();
if (SimpleValue == null)
return typeof (object);
if (Type.IsEnum)
return typeof (string);
return SimpleValue.GetType();
}

#endregion
Expand Down

0 comments on commit 36cbcbd

Please sign in to comment.