Skip to content

Instantly share code, notes, and snippets.

@codedecay
codedecay / Cacheability.cs
Last active August 29, 2015 14:27 — forked from bradwilson/Cacheability.cs
Using chaining to create cached results in ASP.NET Web API v2
public enum Cacheability
{
NoCache,
Private,
Public,
}
@codedecay
codedecay / gist:23548b798672c796c419
Last active August 29, 2015 14:27 — forked from DamianEdwards/gist:4030394
Async site scraping in ASP.NET 4.5
public class SiteScrape : HttpTaskAsyncHandler
{
public override async Task ProcessRequestAsync(HttpContext context)
{
using (var http = new HttpClient())
{
var downloadTasks = new List<Task<string>> {
http.GetStringAsync("http://bing.com"),
http.GetStringAsync("http://google.com"),
http.GetStringAsync("http://oredev.org"),
@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>
@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 / 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 / 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 / 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 / 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 / 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 / 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