Skip to content

Instantly share code, notes, and snippets.

View JoshClose's full-sized avatar

Josh Close JoshClose

View GitHub Profile
@JoshClose
JoshClose / File2.cs
Created November 15, 2011 15:08
How Safe is the Using Block?
var proxy = new MyProxy();
try
{
// Do some work.
proxy.Close();
}
catch( CommunicationException ex )
{
proxy.Abort();
}
@JoshClose
JoshClose / ColorExtensions.cs
Created November 15, 2011 15:21
Changing Color Tint with C#
public static class ColorExtensions
{
/// <summary>
/// Tints the color by the given percent.
/// </summary>
/// <param name="color">The color being tinted.</param>
/// <param name="percent">The percent to tint. Ex: 0.1 will make the color 10% lighter.</param>
/// <returns>The new tinted color.</returns>
public static Color Lighten( this Color color, float percent )
{
@JoshClose
JoshClose / ColorUserType.cs
Created November 15, 2011 15:44
NHibernate Mapping to System.Drawing.Color
public class ColorUserType : IUserType
{
public object Assemble( object cached, object owner )
{
return cached;
}
public object DeepCopy( object value )
{
return value;
@JoshClose
JoshClose / Criteria.cs
Created November 15, 2011 15:51
The New World of NHibernate
// This:
session.CreateCriteria( typeof( MyClass ) ).Add( Expression.Eq( "Name", name ) );
// Becomes this:
session.CreateCriteria( typeof( MyClass ) ).Add<MyClass>( m => m.Name == name ).List();
@JoshClose
JoshClose / Example1.xml
Created November 15, 2011 16:39
Creating a Custom Window in WPF
<Window x:Class="CustomWindow.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
Title="Window1" Height="300" Width="300">
<Grid>
</Grid>
</Window>
@JoshClose
JoshClose / Example1.xml
Created November 15, 2011 16:51
Creating a Common Window in WPF
<ControlTemplate TargetType="Window" x:Key="WindowTemplate">
<aero:SystemDropShadowCrome CornerRadius="10" Margin="10">
<Border BorderThickness="1" BorderBrush="Black" Background="White"
CornerRadius="10">
<Border Height="40" Background="#01000000" VerticalAlignment="Top"
CornerRadius="10,10,0,0" MouseLeftButtonDown="DragWindow">
<ContentPresenter />
</Border>
</Border>
</aero:SystemDropShadowCrome>
@JoshClose
JoshClose / Example1.xml
Created November 15, 2011 17:15
Making a Custom Window Resizable in WPF
<aero:SystemDropShadowChrome CornerRadius="10" Margin="10">
<Border BorderThickness="1" BorderBrush="Black" Background="White"
Margin="0" CornerRadius="10">
<Grid>
<Border Height="40" Background="#01000000" VerticalAlignment="Top"
CornerRadius="10,10,0,0" MouseLeftButtonDown="DragWindow" />
<Rectangle x:Name="ResizeN" Fill="Yellow" VerticalAlignment="Top"
Height="4" Margin="9,-2,9,0" MouseEnter="DisplayResizeCursor"
MouseLeave="ResetCursor" PreviewMouseLeftButtonDown="Resize" />
<Rectangle x:Name="ResizeE" Fill="Yellow" HorizontalAlignment="Right"
@JoshClose
JoshClose / Example1.cs
Created December 2, 2011 02:41
Navigating to the Current Page on WP7
var uri = new Uri( string.Format( "{0}?unique={1}", "SamePage.xaml, Guid.NewGuid() ), UriKind.RelativeOrAbsolute );
RemoveBackEntry = true;
NavigationService.Navigate( uri );
using Irony.Parsing;
namespace Irony.Samples.SQLite
{
[Language( "SQLite", "3", "SQLite Grammar" )]
// ReSharper disable once InconsistentNaming
public class SQLiteGrammar : Grammar
{
public SQLiteGrammar() : base( false )
{
Id Name
1 one
2 two