Skip to content

Instantly share code, notes, and snippets.

View jchadwick's full-sized avatar

Jess Chadwick jchadwick

View GitHub Profile
@jchadwick
jchadwick / Upgrade-Package.ps1
Created July 14, 2011 14:29 — forked from chaliy/Upgrade-Package.ps1
Script to upgrade all NuGet packages in solution to new version
###########################################################
#
# Script to upgrade all NuGet packages in solution to latest version
# https://gist.github.com/1082558
#
# USAGE
# Place this file (Upgrade-Packages.ps1) to your solution folder.
# From Package Manager Console execute
#
# .\Upgrade-Packages.ps1 -PackageFilter:Castle.*
@jchadwick
jchadwick / JsonModelBinder.cs
Created September 13, 2011 18:28
JsonModelBinder
using System.Web.Mvc;
using Newtonsoft.Json;
public class JsonModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var providerResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
var json = providerResult.AttemptedValue;
@jchadwick
jchadwick / JsonpResult.cs
Created December 20, 2011 19:04
ASP.NET MVC ActionResult for JSONP responses
public class JsonpResult : ContentResult
{
public object Model { get; set; }
public string Callback { get; set; }
public JsonpResult()
{
ContentType = "application/javascript";
}
@jchadwick
jchadwick / ExpressionHelpers.cs
Created December 27, 2011 17:18
Expression helpers
using System;
using System.Linq.Expressions;
using System.Reflection;
public static class ExpressionHelpers
{
public static T GetValue<T>(this Expression<Func<T>> source)
{
T unknownValue = source.Compile().Invoke();
@jchadwick
jchadwick / JsonValueProviderFactory.cs
Created February 6, 2012 14:21
JsonValueProviderFactory
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Script.Serialization;
public class JsonValueProviderFactory : ValueProviderFactory
{
public JsonValueProviderFactory(string keyName, Type modelType)
@jchadwick
jchadwick / UrlExtensions.cs
Created March 7, 2012 18:32
External URL Helpers
using System;
using System.Web;
using System.Web.Mvc;
public static class UrlExtensions
{
public static string ExternalAction(this UrlHelper url, string actionName, string controllerName, object routeValues = null)
{
var requestUrl = url.Action(actionName, controllerName, routeValues);
return ExternalUrl(url, requestUrl);
@jchadwick
jchadwick / install.ps1
Created March 23, 2012 18:51
NuGet install.ps1 script that overwrites existing file
param($installPath, $toolsPath, $package, $project)
Write-Host "Setting Application to DowJones.Web.Mvc.HttpApplication..."
# Read the transformed text from the custom template included in the package
$customGlobalAsax = $project.ProjectItems | where { $_.Name -eq "Global.asax.cs.custom" }
$customGlobalAsax.Open()
$customGlobalAsax.Document.Activate()
$customGlobalAsax.Document.Selection.SelectAll();
$replacementGlobalAsax = $customGlobalAsax.Document.Selection.Text;
@jchadwick
jchadwick / status.ps1
Created April 4, 2012 02:15
PowerShell Source Control Status
function status() {
if(Test-Path .svn) {
Write-Host
svn status
Write-Host
}
if(Test-Path .git) {
git status
}
@jchadwick
jchadwick / JsonRoleProvider.cs
Created April 4, 2012 19:36
Json Role Provider
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Script.Serialization;
public class Roles : List<Role>
{
public Roles(IEnumerable<Role> roles = null)
: base(roles ?? Enumerable.Empty<Role>())
@jchadwick
jchadwick / HtmlHelperEnumExtensions.cs
Created April 5, 2012 20:55
ASP.NET MVC Enum Drop-Down List
using System.Web.Mvc;
using System.Web.Mvc.Html;
public static class HtmlHelperEnumExtensions
{
public static IHtmlString EnumDropDownListFor<TModel, TEnum>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TEnum>> field, TEnum selectedValue = default(TEnum))
where TEnum : struct
{
var name = (field.Body as MemberExpression).Member.Name;