Skip to content

Commit

Permalink
Allow overriding SetGriddlyDefault via parameter value
Browse files Browse the repository at this point in the history
  • Loading branch information
programcsharp committed May 13, 2015
1 parent 33bef44 commit 28ea57b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Build/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.1.4")]
[assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.5")]
27 changes: 21 additions & 6 deletions Griddly.Mvc/GriddlyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,41 @@ public static HtmlString AttributeIf(this HtmlHelper helper, string name, bool s
public static void SetGriddlyDefault<T>(this Controller controller, ref T parameter, string field, T value)
{
if (controller.ControllerContext.IsChildAction)
parameter = value;
{
if (EqualityComparer<T>.Default.Equals(parameter, default(T)))
parameter = value;

controller.ViewData["_griddlyDefault_" + field] = value;
controller.ViewData["_griddlyDefault_" + field] = parameter;
}
else
controller.ViewData["_griddlyDefault_" + field] = value;
}

public static void SetGriddlyDefault<T>(this Controller controller, ref T[] parameter, string field, IEnumerable<T> value)
{
if (controller.ControllerContext.IsChildAction)
parameter = value.ToArray();
{
if (parameter == null)
parameter = value.ToArray();

controller.ViewData["_griddlyDefault_" + field] = value;
controller.ViewData["_griddlyDefault_" + field] = parameter;
}
else
controller.ViewData["_griddlyDefault_" + field] = value;
}

public static void SetGriddlyDefault<T>(this Controller controller, ref T?[] parameter, string field, IEnumerable<T> value)
where T : struct
{
if (controller.ControllerContext.IsChildAction)
parameter = value.Cast<T?>().ToArray();
{
if (parameter == null)
parameter = value.Cast<T?>().ToArray();

controller.ViewData["_griddlyDefault_" + field] = value;
controller.ViewData["_griddlyDefault_" + field] = parameter;
}
else
controller.ViewData["_griddlyDefault_" + field] = value;
}

public static object GetGriddlyDefault(this WebViewPage page, string field)
Expand Down

0 comments on commit 28ea57b

Please sign in to comment.