Skip to content

Instantly share code, notes, and snippets.

@kevinbrechbuehl
kevinbrechbuehl / ContentSearchTest.cs
Created July 22, 2015 11:23
Sitecore Content Search Unit Test
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Moq;
using NUnit.Framework;
using Sitecore.ContentSearch;
using Sitecore.ContentSearch.Linq;
using Sitecore.ContentSearch.SearchTypes;
@kevinbrechbuehl
kevinbrechbuehl / DisableGlassMapperCache.cs
Created June 24, 2015 16:18
Disable Glass Mapper Cache
/// <summary>
/// Disables the cache for Glass Mapper. This is used for the content management server
/// as we don't want to use it here.
/// </summary>
public class DisableGlassMapperCache
{
/// <summary>
/// Processes the specified arguments.
/// </summary>
/// <param name="args">The arguments.</param>
@kevinbrechbuehl
kevinbrechbuehl / RenderingModelBase.cs
Created May 31, 2014 18:22
Base class for view rendering models
public abstract class RenderingModelBase : RenderingModel
{
protected T GetGlassItem<T>()
{
return RenderingContext.CurrentOrNull.Rendering.Item.GlassCast<T>();
}
}
public class ValidateFormHandler : ActionMethodSelectorAttribute
{
/// <summary>
/// Determines whether the current action is valid for this request.
/// </summary>
/// <param name="controllerContext">The controller context.</param>
/// <param name="methodInfo">The method information.</param>
/// <returns>Boolean value if request is valid</returns>
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
{
public class UnicHelper : Sitecore.Mvc.Helpers.SitecoreHelper
{
/// <summary>
/// The controller field name
/// </summary>
public const string ControllerFieldName = "fhController";
/// <summary>
/// The action field name
/// </summary>
@kevinbrechbuehl
kevinbrechbuehl / UsingVar.cs
Created March 8, 2013 08:50
Good and bad examples of using the var keyword in C#
// good design
var numbers = new int[] {1, 2, 3, 4};
var stringBuilder = new StringBuilder();
var letters = new List();
var keywords = new Dictionary();
// OK (but prefer explicit declaration)
var pages = 10; // int, long, what to expect?
var username = "Kevin";
var order = GetOrder(orderId); // ok if the type is Order, otherwise not