Created
December 23, 2013 15:59
-
-
Save anonymous/8099521 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using System.Reflection | |
@helper DumpModel(dynamic obj) { | |
var uuid = string.Format("dump-model-table-{0}", Guid.NewGuid().ToString("N")); | |
<style> | |
.-dumped-model-table, | |
.-dumped-model-table > caption { | |
font-size: 11px; | |
} | |
.-dumped-model-table > caption { | |
background-color: #000; | |
color: #fff; | |
} | |
.-dumped-model-table { | |
background-color: #FFF; | |
position: fixed; | |
top: 5px; | |
right: 5px; | |
z-index: 9999; | |
} | |
</style> | |
<table id="@uuid" class="-dumped-model-table table-bordered table-condensed"> | |
<caption>@obj.GetType().Name</caption> | |
<thead> | |
<tr> | |
<th width="1px">Type</th> | |
<th width="1px">Name</th> | |
<th width="1px">Value</th> | |
<th width="1px"><a onclick="document.getElementById('@uuid').remove()">×</a></th> | |
</tr> | |
</thead> | |
<tbody> | |
@foreach(PropertyInfo prop in obj.GetType().GetProperties()) | |
{ | |
var typeName = prop.PropertyType.Name.ToString(); | |
var propName = prop.Name; | |
var propValue = prop.GetValue(obj, null) ?? "null"; | |
var isValue = propValue.GetType().IsValueType; | |
var propValueString = string.Empty; | |
if (isValue) { | |
propValueString = propValue.ToString(); | |
} else { | |
propValueString = propValue.GetType().Name; | |
} | |
<tr> | |
<td>@typeName</td> | |
<td>@propName</td> | |
<td>@if (!isValue) | |
{ | |
@:[@propValueString] | |
} | |
else { | |
@propValueString | |
} | |
</td> | |
<td>@if (!isValue) { | |
@:+ | |
} | |
</td> | |
</tr> | |
} | |
</tbody> | |
</table> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment