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 class PercentComplete : IDisposable | |
{ | |
private readonly float _max; | |
private readonly float _min; | |
private readonly int _total; | |
private int _current; | |
public PercentComplete(int total) | |
: this(total, 0, 100) | |
{ |
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 class EnsureDataBound : Control | |
{ | |
private int _count; | |
public bool AllowMultiple { get; set; } | |
public bool EveryPostBack { get; set; } | |
public When When { get; set; } | |
public override void DataBind() | |
{ |
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 string ResolveUrl(string url) | |
{ | |
string appDomainAppVirtualPath = HttpRuntime.AppDomainAppVirtualPath; | |
return url.StartsWith("~/") ? appDomainAppVirtualPath + url.Substring(appDomainAppVirtualPath != null && appDomainAppVirtualPath.EndsWith("/") ? 2 : 1) : url; | |
} | |
public static string ResolveUrl(string url, object queryStringParams, bool skipEmptyValues = true) | |
{ | |
if (queryStringParams == null) return ResolveUrl(url); | |
var sb = new StringBuilder(ResolveUrl(url)); |
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 public string ToStringAddSpaces(this Enum value) | |
{ | |
string a = value.ToString(); | |
return PascalCaseAddSpaces(a); | |
} | |
static public string[] PascalCaseToWords(string value) | |
{ | |
return Regex.Split(value, "(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])"); | |
} |
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> Unpage<T>(Func<int, int, IEnumerable<T>> func, int batchSize) | |
{ | |
int skip = 0; | |
int count; | |
do | |
{ | |
count = 0; | |
foreach (var a in func(skip, batchSize)) | |
{ | |
count++; |
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 TValue GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dic, TKey key, TValue defaultVal = default(TValue)) | |
{ | |
TValue ret; | |
return dic.TryGetValue(key, out ret) ? ret : defaultVal; | |
} | |
public static TValue GetValueOrDefault<TValue>(this StateBag stateBag, string key, TValue defaultValue = default(TValue)) | |
{ | |
object value = stateBag[key]; | |
return Equals(value, null) ? defaultValue : (TValue) value; |
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
; Variables definition | |
; ----------------------------------------------------------------------------- | |
EnvGet, userProfile, USERPROFILE | |
Software := userProfile . "\Dropbox\software\" | |
; Launch or toggle program, http://lifehacker.com/5468862/create-a-shortcut-key-for-restoring-a-specific-window | |
; ----------------------------------------------------------------------------- | |
ToggleWinMinimize(WindowTitle) | |
{ | |
SetTitleMatchMode,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
public static TValue GetOrSet<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> create) | |
{ | |
TValue value; | |
return dictionary.TryGetValue(key, out value) ? value : (dictionary[key] = create(key)); | |
} | |
public static TValue GetOrSet<TKey, TValue>(this IDictionary dictionary, TKey key, Func<TKey, TValue> create) | |
{ | |
var value = (TValue) dictionary[key]; | |
if (!Equals(value, default(TValue))) return value; |
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 AsteriskValidation | |
{ | |
public static void Validate(this Page page, IValidatableObject validatableObject, ValidationContext context = null) | |
{ | |
foreach (ValidationResult error in validatableObject.Validate(context)) | |
page.Validators.Add(new ErrorValidator(error)); | |
} | |
public static void Validate(this Page page, DbEntityValidationException ex, ValidationContext context = null) | |
{ |
OlderNewer