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<TResult> LeftJoin<TSource, TInner, TKey, TResult>(this IEnumerable<TSource> source, | |
IEnumerable<TInner> inner, | |
Func<TSource, TKey> pk, | |
Func<TInner, TKey> fk, | |
Func<TSource, TInner, TResult> result) | |
{ | |
IEnumerable<TResult> _result = Enumerable.Empty<TResult>(); | |
_result = from s in source | |
join i in inner |
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 void ConsoleWrite(ConsoleColor color, string text) | |
{ | |
ConsoleColor originalColor = Console.ForegroundColor; | |
Console.ForegroundColor = color; | |
Console.Write(text); | |
Console.ForegroundColor = originalColor; | |
} | |
public static void ConsoleWriteLine(ConsoleColor color, string text) | |
{ |
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<DateTime> GetDateRangeTo(this DateTime self, DateTime toDate) | |
{ | |
var range = Enumerable.Range(0, new TimeSpan(toDate.Ticks - self.Ticks).Days); | |
return from p in range select self.Date.AddDays(p); | |
} |
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 Dictionary<TFirstKey, Dictionary<TSecondKey, TValue>> Pivot<TSource, TFirstKey, TSecondKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TFirstKey> firstKeySelector, Func<TSource, TSecondKey> secondKeySelector, Func<IEnumerable<TSource>, TValue> aggregate) | |
{ | |
var retVal = new Dictionary<TFirstKey, Dictionary<TSecondKey, TValue>>(); | |
var l = source.ToLookup(firstKeySelector); | |
foreach (var item in l) | |
{ | |
var dict = new Dictionary<TSecondKey, TValue>(); | |
retVal.Add(item.Key, dict); | |
var subdict = item.ToLookup(secondKeySelector); |
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<IEnumerable<T>> Batch<T>(this IEnumerable<T> collection, int batchSize) | |
{ | |
List<T> nextbatch = new List<T>(batchSize); | |
foreach (T item in collection) | |
{ | |
nextbatch.Add(item); | |
if (nextbatch.Count == batchSize) | |
{ | |
yield return nextbatch; | |
nextbatch = new List<T>(batchSize); |
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 partial class CheckBoxList | |
{ | |
#region String Expression | |
public static MvcHtmlString CheckBoxListItem(this HtmlHelper htmlHelper, string name, string value) | |
{ | |
return CheckBoxListItem(htmlHelper, name, value, false, (object)null /* htmlAttributes */); | |
} |
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 partial class MyEnumDropDownList | |
{ | |
#region Enum DropDown | |
public static MvcHtmlString EnumDropDownListFor<TModel, TEnum>(this HtmlHelper<TModel> htmlHelper, | |
Expression<Func<TModel, TEnum>> expression) | |
{ | |
return EnumDropDownListFor(htmlHelper, expression, 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
public static class JSONHelper | |
{ | |
public static string ToJSON(this object obj) | |
{ | |
TimeZoneInfo tzi = TimeZoneInfo.Local; | |
JavaScriptSerializer serializer = new JavaScriptSerializer(); | |
return serializer.Serialize(obj.SpecifyDateTimeKind()); | |
} |
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.Text.RegularExpressions; | |
public static class EMailValidator | |
{ | |
static Regex ValidEmailRegex = CreateValidEmailRegex(); | |
private static Regex CreateValidEmailRegex() | |
{ | |
string validEmailPattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|" | |
+ @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)" | |
+ @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$"; |
OlderNewer