Skip to content

Instantly share code, notes, and snippets.

Created December 23, 2013 15:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8099521 to your computer and use it in GitHub Desktop.
Save anonymous/8099521 to your computer and use it in GitHub Desktop.
@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()">&times;</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