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
/// <summary> | |
/// Represents a wildcard running on the | |
/// <see cref="System.Text.RegularExpressions"/> engine. | |
/// </summary> | |
public class Wildcard : Regex | |
{ | |
/// <summary> | |
/// Initializes a wildcard with the given search pattern. | |
/// </summary> | |
/// <param name="pattern">The wildcard pattern to match.</param> |
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
/// <summary> | |
/// http://www.codeproject.com/Tips/197531/Do-not-use-using-for-WCF-Clients | |
/// </summary> | |
public static class WcfExtensions | |
{ | |
public static void Using<T>(this T client, Action<T> work) | |
where T : ICommunicationObject | |
{ | |
try | |
{ |
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
/* This package contains a powerful, declarative command-line parsing system in a single .cs file. | |
* You can include this in any project with almost zero footprint and very easy/readable usage, | |
* as shown below. More switch types, including generic ones are coming soon. Visit the project | |
* page for a sample of how to use this handy package. Part of Code Blocks (http://codeblocks.codeplex.com) | |
*/ | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.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 class KeyboardHook | |
{ | |
#region pinvoke details | |
private enum HookType : int | |
{ | |
WH_JOURNALRECORD = 0, | |
WH_JOURNALPLAYBACK = 1, | |
WH_KEYBOARD = 2, | |
WH_GETMESSAGE = 3, |
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
// Credits: http://stackoverflow.com/a/778133/24472 | |
[DllImport("user32.dll", EntryPoint = "SendMessageA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)] | |
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); | |
private const int WM_SETREDRAW = 0xB; | |
public static void SuspendDrawing(this Control target) | |
{ | |
SendMessage(target.Handle, WM_SETREDRAW, 0, 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
// Usage : | |
textBoxChangedEventMask = new EventMask( | |
() => { textBox1.TextChanged += new EventHandler(textBox1_TextChanged); }, | |
() => { textBox1.TextChanged -= new EventHandler(textBox1_TextChanged); } | |
); | |
//in the event code: | |
try | |
{ |
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
int GetDataGridViewHeight(DataGridView dataGridView) | |
{ | |
var sum = dataGridView.ColumnHeadersVisible ? dataGridView.ColumnHeadersHeight : 0 + | |
dataGridView.Rows.OfType<DataGridViewRow>().Where(r => r.Visible).Sum(r => r.Height); | |
return sum; | |
} |
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 GetEnvironment(string environmentVariableName, string defaultValue) | |
{ | |
var Parameter = Environment.GetEnvironmentVariable(environmentVariableName, EnvironmentVariableTarget.Machine); | |
if (!string.IsNullOrEmpty(Parameter)) | |
return Parameter; | |
Environment.SetEnvironmentVariable(environmentVariableName, defaultValue, EnvironmentVariableTarget.Machine); | |
return defaultValue; | |
} |
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 T Max<T>(T x, T y) | |
{ | |
return (Comparer<T>.Default.Compare(x, y) > 0) ? x : y; | |
} | |
static T Min<T>(T x, T y) | |
{ | |
return (Comparer<T>.Default.Compare(x, y) > 0) ? y : x; | |
} |
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
DateTime truncateMs(DateTime date) | |
{ | |
return new DateTime((date.Ticks / TimeSpan.TicksPerSecond) * TimeSpan.TicksPerSecond); | |
} |