Skip to content

Instantly share code, notes, and snippets.

@codedecay
codedecay / FakeDbSet.cs
Last active August 29, 2015 14:27 — forked from LukeWinikates/FakeDbSet.cs
An implementation of IDbSet to help with mocking Entity Framework DbContexts.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EntityExtensions {
public class FakeDbSet<T> : System.Data.Entity.IDbSet<T> where T : class {
private readonly List<T> list = new List<T>();
public FakeDbSet() {
@codedecay
codedecay / Program.cs
Last active August 29, 2015 14:27 — forked from panesofglass/Program.cs
Example of using end-to-end dynamic in a C# Web API project using Dapper for data access.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlServerCe;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
@codedecay
codedecay / EFExtensions.cs
Last active August 29, 2015 14:27 — forked from x4m/EFExtensions.cs
C# extension for executing upsert (MERGE SQL command) in EF with MSSQL
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
namespace EFExtensions
@codedecay
codedecay / EFExtensions.cs
Last active August 29, 2015 14:27 — forked from ondravondra/EFExtensions.cs
C# extension for executing upsert (MERGE SQL command) in EF with MSSQL
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
namespace EFExtensions
@codedecay
codedecay / CollectionExtensions.cs
Last active August 29, 2015 14:27 — forked from sitefinitysteve/CollectionExtensions.cs
SitefinitySteve Extension Collection, included in the RandomSiteControls
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Telerik.Sitefinity
{
public static class CollectionExtensions
{
/// <summary>
@codedecay
codedecay / gist:7cfea0c3d75e43279015
Last active August 29, 2015 14:27 — forked from Fodsuk/gist:3025099
service layer exampe
public class InventoryController : ApiController
{
private readonly IInventoryManagementService _inventoryManagementService;
private readonly IUnitOfWork _unitOfWork;
public InventoryController(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork; //access services
_inventoryManagementService = _unitOfWork.Get<IInventoryManagementService>();
}
@codedecay
codedecay / BaseController.cs
Last active August 29, 2015 14:27 — forked from jpoehls/BaseController.cs
Newtonsoft Json Results for MVC
using System;
using System.Linq;
using System.Web.Mvc;
public abstract class BaseController : Controller
{
protected override JsonResult Json(object data, string contentType, System.Text.Encoding contentEncoding)
{
return new JsonNetResult
{
@codedecay
codedecay / TypeSwitch.cs
Last active August 29, 2015 14:27 — forked from Virtlink/TypeSwitch.cs
Switch on type. The order of the Case() methods is important.
using System;
namespace Virtlink
{
/// <summary>
/// Executes a particular piece of code based on the type of the argument.
/// </summary>
/// <example>
/// Usage example:
/// <code>
@codedecay
codedecay / FindConflictingReferences.cs
Last active August 29, 2015 14:27 — forked from brianlow/FindConflictingReferences.cs
Find conflicting assembly references
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
namespace MyProject
{
[TestFixture]
@codedecay
codedecay / Either.cs
Last active August 29, 2015 14:27 — forked from siliconbrain/Either.cs
Implemetation of Haskell's Either type in C#
/// <summary>
/// Interface definition of Either
/// </summary>
/// <typeparam name="Tl">type of the Left value</typeparam>
/// <typeparam name="Tr">type of the Right value</typeparam>
public interface IEither<out Tl, out Tr>
{
/// <summary>
/// Check the type of the value held and invoke the matching handler function
/// </summary>