Skip to content
Browse files

recursive object dump

  • Loading branch information...
1 parent ab16407 commit 737cff0ed3ee6c9d2b4b67c541d099dfd5e3a90f Tim Iles committed Apr 1, 2012
Showing with 38 additions and 14 deletions.
  1. +11 −11 GoCardlessSdk/Helpers/Utils.cs
  2. +25 −1 Sample.Mvc3/App_Code/Helpers.cshtml
  3. +2 −2 Sample.Mvc3/Views/Home/Index.cshtml
View
22 GoCardlessSdk/Helpers/Utils.cs
@@ -103,15 +103,15 @@ internal static string ToUrlString(this object o)
internal static HashParams ToHashParams(
this object queryStringable, HashParams hash = null, string prefix = null)
{
- Func<object, bool> isSimpleType = o =>
- {
- var type = o.GetType();
- return type.IsPrimitive
- || type == typeof (string)
- || type == typeof (decimal)
- || type == typeof (DateTimeOffset)
- ;
- };
+ Func<object, bool> isOfSimpleType = o =>
+ {
+ var type = o.GetType();
+ return type.IsPrimitive
+ || type == typeof (string)
+ || type == typeof (decimal)
+ || type == typeof (DateTimeOffset)
+ ;
+ };
PropertyInfo[] propertyInfos = queryStringable.GetType().GetProperties(
BindingFlags.Public | BindingFlags.Instance);
@@ -133,7 +133,7 @@ internal static string ToUrlString(this object o)
{
foreach (var innerValue in (Array)value)
{
- if (isSimpleType(innerValue))
+ if (isOfSimpleType(innerValue))
{
hash.Add(propertyName + "[]", innerValue);
}
@@ -143,7 +143,7 @@ internal static string ToUrlString(this object o)
}
}
}
- else if (isSimpleType(value))
+ else if (isOfSimpleType(value))
{
hash.Add(propertyName, value);
}
View
26 Sample.Mvc3/App_Code/Helpers.cshtml
@@ -1,6 +1,19 @@
@using System.Collections
@helper Dump(object model)
{
+ Func<object, bool> isOfSimpleType = o =>
+ {
+ if (o == null)
+ {
+ return true;
+ }
+ var type = o.GetType();
+ return type.IsPrimitive
+ || type == typeof(string)
+ || type == typeof(decimal)
+ || type == typeof(DateTimeOffset)
+ ;
+ };
if (model is IEnumerable)
{
int item = 0;
@@ -28,7 +41,18 @@
<tr>
<td>@prop.Name
</td>
- <td>@prop.GetValue(model, new object[0])
+ <td>
+ @{
+ var value = prop.GetValue(model, new object[0]);
+ if (isOfSimpleType(value))
+ {
+ @value
+ }
+ else
+ {
+ @Dump(value)
+ }
+ }
</td>
</tr>
}
View
4 Sample.Mvc3/Views/Home/Index.cshtml
@@ -14,9 +14,9 @@ else
<a href="@Model.NewBillUrl">Create new bill</a>
</p>
<p>
- <a href="@Model.NewSubscriptionUrl">Create new subscription</a>
+ <a href="@Model.NewPreAuthorizationUrl">Create new preauthorization</a>
</p>
<p>
- <a href="@Model.NewPreAuthorizationUrl">Create new preauthorization</a>
+ <a href="@Model.NewSubscriptionUrl">Create new subscription</a>
</p>
}

0 comments on commit 737cff0

Please sign in to comment.
Something went wrong with that request. Please try again.