Skip to content

Instantly share code, notes, and snippets.

View rally25rs's full-sized avatar

Jeff Valore rally25rs

View GitHub Profile
@rally25rs
rally25rs / CodeSample1.cs
Created May 10, 2011 00:27
Code Sample 1 (DynamicMethods and ILEmit)
/* ***
* This is a method from an object-relation-mapping (ORM) tool that I had started to write.
* I eventually stopped working on it, ad instead contributed time to the open source
* SubSonic project instead.
*
* This method is an example of generating DynamicMethods to be used at runtime to check and
* set some properties any an arbitrary type. This was used over straight reflection every time
* because reflection can be fairly slow. The use of a DynamicMethod is much quicker.
* *** */
@rally25rs
rally25rs / CodeSample2.cs
Created May 10, 2011 00:47
Code Sample 2 (factory pattern)
/* ***
* This sample is again from an ORM tool that I had been working on.
*
* This is simply an example of a "factory" pattern that I wrote a few years ago.
* This factory is designed to return the same IDataBinder instance when the same
* database connection string is passed in.
* *** */
@rally25rs
rally25rs / HtmlHelperDisplayNameExtensions.cs
Created November 20, 2011 03:29
Extension methods for ASP.NET MVC3 that provide helpers for getting display names from IEnumerable models.
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web.Mvc;
namespace Web.Extensions
{
public static class HtmlHelperDisplayNameExtensions
{
/// <summary>
@rally25rs
rally25rs / FakeDbSet.cs
Created December 18, 2011 02:11
Fake implementation of Entity Framework IDbSet to use for unit testing.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
namespace Rally25rs.Gist.Data
{
@rally25rs
rally25rs / AssertMvc.cs
Created January 8, 2012 15:16
MSTest Assert Utility for MVC3 Controller Unit Testing
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
/// <summary>
/// MSTest Asserts for unit testing MVC3 Controllers.
/// </summary>
public static class AssertMvc
{
public static T ResultIs<T>(object result)
where T : ActionResult
@rally25rs
rally25rs / MvcMockHelpers.cs
Created January 8, 2012 15:26
MvcMockHelpers.cs - Helper Utility for Mocking MVC3 Controllers with Moq.
using System;
using System.Collections.Specialized;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Moq;
/// <summary>
/// This helper class can be used to set up Moq mocks of MVC3 controllers.
/// Slightly modified from the original version from Scott Hanselman's blog:
@rally25rs
rally25rs / AnythingToCs.cs
Created April 5, 2012 11:56
Anything to CSV
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace AnythingToCsv
{
public static class EnumerableExtensions
{
@rally25rs
rally25rs / JsonEncodeAnExpandoObjectByWrappingItInADynamicJsonObject.cs
Created July 3, 2012 20:09
Serialize an ExpandoObject to a JSON string by wrapping it in a DynamicJsonObject
// By default, Json.Encode will turn an ExpandoObject into an array of items,
// because internally an ExpandoObject extends IEnumerable<KeyValuePair<string, object>>.
// You can turn it into a non-list JSON string by first wrapping it in a DynamicJsonObject.
[TestMethod]
public void JsonEncodeAnExpandoObjectByWrappingItInADynamicJsonObject()
{
dynamic expando = new ExpandoObject();
expando.Value = 10;
expando.Product = "Apples";
@rally25rs
rally25rs / .gitignore
Created August 9, 2012 11:58
.gitignore for .NET projects.
# .gitignore for .NET projects
# Standard VS.NET
obj
bin
*.csproj.user
*.suo
*.cache
Thumbs.db
@rally25rs
rally25rs / kendo.binders.class.js
Created August 4, 2014 12:03
Class MVVM binder for Kendo UI
kendo.data.binders.class = kendo.data.Binder.extend({
init: function (target, bindings, options) {
kendo.data.Binder.fn.init.call(this, target, bindings, options);
// get list of class names from our complex binding path object
this._lookups = [];
for (var key in this.bindings.class.path) {
this._lookups.push({
key: key,
path: this.bindings.class.path[key]