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
double Median<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector) | |
{ | |
if (!source.Any()) throw new InvalidOperationException(); | |
var sorted = source.OrderBy(selector); | |
var count = (int)(sorted.Count()); | |
int index = count / 2; |
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() | |
{ | |
var x = 1; | |
Unless(x == 0, () => Console.WriteLine("A")); | |
Unless(x == 0, () => Console.WriteLine("A"), () => Console.WriteLine("B")); | |
Console.WriteLine(Unless(x == 0, () => "A")); | |
Console.WriteLine(Unless(x == 0, () => "A", () => "B")); | |
} |
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.Linq; | |
using System.Threading; | |
namespace ConsoleApplication2 | |
{ | |
/// <summary> | |
/// static の悪夢 | |
/// </summary> | |
class Program |
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 Scala | |
{ | |
public static Func<T, V> Compose<T, U, V>(this Func<U, V> first, Func<T, U> second) | |
{ | |
if (first == null) throw new ArgumentNullException("first"); | |
if (second == null) throw new ArgumentNullException("second"); | |
return t => first(second(t)); | |
} |
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.Threading; | |
namespace Mjollnir | |
{ | |
public class AsyncResult : IAsyncResult, IDisposable | |
{ | |
public AsyncResult(AsyncCallback callback, object state) | |
{ | |
// callback can be null. |
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
static class DictionaryExtensions | |
{ | |
public static T GetValueOrDefault<T>(this IDictionary<string, object> source, string name) | |
{ | |
if (source == null) throw new ArgumentNullException("source"); | |
if (name == null) throw new ArgumentNullException("name"); | |
var value = default(object); | |
return (source.TryGetValue(name, out value) && (value is T)) |
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
static string GetDisplayName<TModel>(Expression<Func<TModel, object>> expression) | |
{ | |
var type = typeof(TModel); | |
var propertyList = default(IEnumerable<string>); | |
switch (expression.Body.NodeType) | |
{ | |
case ExpressionType.Convert: | |
case ExpressionType.ConvertChecked: | |
var ue = expression.Body as UnaryExpression; |
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.Text; | |
namespace Mjollnir | |
{ | |
static class StringFactory | |
{ | |
public static string Create(Action<StringBuilder> action) | |
{ | |
if (action == null) throw new ArgumentNullException("action"); |
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
static class Syncronized | |
{ | |
public static void Invoke(Action<ManualResetEvent> action) | |
{ | |
if (action == null) throw new ArgumentException("action"); | |
using (var signal = new ManualResetEvent(false)) | |
{ | |
action(signal); | |
signal.WaitOne(); |
OlderNewer