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
namespace Mvc.ResourceLoader.Util { | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.IO; | |
public class JoinedStreamReader : Stream { |
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
// Highly compact JSON beautifier/formatter. Not very efficient and could definitely be improved. The main issue is with | |
// the number of allocations and memory presure being placed on the heap and garbage collector if the input is large. | |
// It is the shortest in terms of code size though. | |
// Source: http://stackoverflow.com/questions/4580397/json-formatter-in-c/24782322#24782322 | |
private const string INDENT_STRING = " "; | |
static string FormatJson(string json) { | |
int indentation = 0; |
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; | |
using System.Linq.Expressions; | |
using System.Reflection; | |
namespace Bleroy.Helpers { | |
public static class NotNull { | |
public static TProp Get<TSource, TProp>(this TSource source, Expression<Func<TSource, TProp>> property) where TSource : class { | |
if (source == null) return default(TProp); | |
var current = property.Body; |
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
void Main() | |
{ | |
// An implementation of the Where method using the SelectMany() method. | |
TestWhere(); | |
// An implementation of Join using the SelectMany() method. | |
TestJoin(); | |
} | |
public static IEnumerable<T> Where<T>(IEnumerable<T> stuffs, Func<T, bool> predicate) |
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
// Full credit goes to Wes Dyer http://blogs.msdn.com/b/wesdyer/archive/2008/01/11/the-marvels-of-monads.aspx | |
// Explanation of how query expressions are translated in to extension method syntax. | |
public class Identity<T> | |
{ | |
public T Value { get; private set; } | |
public Identity(T value) { this.Value = value; } | |
public static implicit operator Identity<T>(T value) { | |
return new Identity<T>(value); |
NewerOlder