This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Get the action names for a particular controller type. | |
public static IEnumerable<String> ActionsFromController(this Type controllerType) | |
{ | |
return controllerType.GetMethods(BindingFlags.Public | BindingFlags.Instance).OfType<MethodInfo>() | |
.Where(y=>typeof(IActionResult).IsAssignableFrom(y)).Select(y=>y.Name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//example expando... | |
public class ExtensibleClass : IFlyweight | |
{ | |
private Dictionary<string, object> _props = new Dictionary<String, object>(); | |
public object this[String key]{ | |
get{ | |
return this._props[key]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
public class MyClass | |
{ | |
public static void RunSnippet() | |
{ | |
DateTime start = DateTime.Now; | |
for(int i = 0; i< 1000000; i++) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<T> Distinct(this IEnumerable<T> set, Func<T,U> propertySelector) | |
{ | |
HashSet<U> distinct = new HashSet<U>(); | |
foreach(var a in set) | |
{ | |
var key = propertySelector.Invoke(a); | |
if(!distinct.Contains(key)) | |
{ | |
distinct.Add(key); | |
yield return a; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ArrayUtils | |
{ | |
public static void Push<T>(this T[] arr, T newItem) | |
{ | |
arr = (new T[] { newItem }).Concat(arr).ToArray(); | |
} | |
public static T Pop<T>(this T[] arr, T newItem) | |
{ | |
T retval = default(T); |
NewerOlder