Skip to content

Instantly share code, notes, and snippets.

@CodeCharm
Last active November 17, 2019 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeCharm/7ecc0b53b8f66026505462490636c0a9 to your computer and use it in GitHub Desktop.
Save CodeCharm/7ecc0b53b8f66026505462490636c0a9 to your computer and use it in GitHub Desktop.
Alan's C# Snippets
// 1.0.0
// aaa => arrangeActAssert
// aaaf => arrangeActAssertFact
// aaat => arrangeActAssertTheory
// sing => singleton
// disp =>
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################
/.vs/
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Arrange/Act/Assert comments</Title>
<Author>Alan McBee</Author>
<Description>Creates arrange/act/assert comments</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>aaa</Shortcut>
</Header>
<Snippet>
<Code Language="csharp" Delimiter="$"><![CDATA[ // arrange
// act
// assert
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Arrange/Act/Assert Fact test comments</Title>
<Author>Alan McBee</Author>
<Description>Creates an XUnit Fact with arrange/act/assert comments</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>aaaf</Shortcut>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>XUnit</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>Xunit</Namespace>
</Import>
</Imports>
<Declarations>
<Literal Editable="true">
<ID>factname</ID>
<ToolTip>Fact name</ToolTip>
<Default>FactPlaceholder</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp" Delimiter="$"><![CDATA[[Fact]
public void $factname$()
{
// arrange
// act
// assert
}
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Arrange/Act/Assert Theory test comments</Title>
<Author>Alan McBee</Author>
<Description>Creates an XUnit Theory with arrange/act/assert comments</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>aaat</Shortcut>
</Header>
<Snippet>
<Imports>
<Import>
<Namespace>Xunit</Namespace>
</Import>
<Import>
<Namespace>Ploeh.AutoFixture.Xunit2</Namespace>
</Import>
</Imports>
<Declarations>
<Literal Editable="true">
<ID>theoryname</ID>
<ToolTip>Theory name</ToolTip>
<Default>TheoryPlaceholder</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>parameterType</ID>
<ToolTip>Parameter type</ToolTip>
<Default>object</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>parameterName</ID>
<ToolTip>Paramater name</ToolTip>
<Default>parameter</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp" Delimiter="$"><![CDATA[[Theory, AutoData]
public void $theoryname$($parameterType$ $parameterName$)
{
// arrange
// act
// assert
}
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Dispose</Title>
<Author>Alan McBee</Author>
<Description>Creates C# IDisposable support methods</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>disp</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="false">
<ID>classname</ID>
<ToolTip>Class name</ToolTip>
<Default>ClassNamePlaceholder</Default>
<Function>ClassName()</Function>
</Literal>
</Declarations>
<Code Language="csharp" Delimiter="$"><![CDATA[#region IDisposable implementation
// Track whether Dispose has been called.
private bool _disposed = false;
// Implement IDisposable.
// Do not make this method virtual.
// A derived class should not be able to override this method.
public void Dispose()
{
Dispose(true);
// Take yourself off the Finalization queue
// to prevent finalization code for this object
// from executing a second time.
GC.SuppressFinalize(this);
}
// Dispose(bool disposing) executes in two distinct scenarios.
// If disposing equals true, the method has been called directly
// or indirectly by a user's code. Managed and unmanaged resources
// can be disposed.
// If disposing equals false, the method has been called by the
// runtime from inside the finalizer and you should not reference
// other objects. Only unmanaged resources can be disposed.
protected virtual void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if (!this._disposed)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if (disposing)
{
// TODO: Dispose managed resources.
}
// Release unmanaged resources. If disposing is false,
// only the following code is executed.
// TODO: Release unmanaged resources
// Note that this is not thread safe.
// Another thread could start disposing the object
// after the managed resources are disposed,
// but before the disposed flag is set to true.
// If thread safety is necessary, it must be
// implemented by the client.
}
_disposed = true;
}
// Use C# destructor syntax for finalization code.
// This destructor will run only if the Dispose method
// does not get called.
// It gives your base class the opportunity to finalize.
// Do not provide destructors in types derived from this class.
~$classname$()
{
// Do not re-create Dispose clean-up code here.
// Calling Dispose(false) is optimal in terms of
// readability and maintainability.
Dispose(false);
}
#endregion
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Dispose - Inherited</Title>
<Description>Creates C# IDisposable support methods for a class that inherits from an IDisposable base class</Description>
<Author>Alan McBee</Author>
<Shortcut>dispi</Shortcut>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Code Language="CSharp">
<![CDATA[
#region IDisposable Members
// Track whether Dispose has been called.
private bool _disposed = false;
// Design pattern for a derived class.
// Note that this derived class inherently implements the
// IDisposable interface because it is implemented in the base class.
// This derived class does not have a Finalize method
// or a Dispose method without parameters because it inherits
// them from the base class.
protected override void Dispose(bool disposing)
{
if (!this.disposed)
{
try
{
if (disposing)
{
// Release the managed resources you added in
// this derived class here.
addedManaged.Dispose();
}
// Release the native unmanaged resources you added
// in this derived class here.
CloseHandle(addedNative);
_disposed = true;
}
finally
{
// Call Dispose on your base class.
base.Dispose(disposing);
}
}
}
#endregion
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Keywords>
<Keyword>Event</Keyword>
<Keyword>ASP.NET</Keyword>
<Keyword>Control</Keyword>
<Keyword>WebControl</Keyword>
</Keywords>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Event - Control</Title>
<Author>Alan McBee</Author>
<Description>Creates a C# style event property construct and methods for an event WITHOUT parameters, for classes which ARE derived from ASP.NET System.Web.Control</Description>
<HelpUrl>http://www.codecharm.com/Home/tabid/61/EntryId/40/Updated-C-Event-snippets.aspx</HelpUrl>
<Shortcut>eventc</Shortcut>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>System.dll</Assembly>
</Reference>
</References>
<Declarations>
<Literal Editable="true">
<ID>EventName</ID>
<ToolTip>Name of the event</ToolTip>
<Default>Event</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>EventCategory</ID>
<ToolTip>Property window category</ToolTip>
<Default>Category</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[#region $EventName$ Event
private static readonly object c_$EventName$Event = new object();
[Category("$EventCategory$")]
public event EventHandler $EventName$
{
add { Events.AddHandler($EventName$Event, value); }
remove { Events.RemoveHandler($EventName$Event, value); }
}
protected virtual void On$EventName$(EventArgs e)
{
EventHandler handler = (EventHandler)Events[$EventName$Event];
if (null != handler)
{
handler(this, e);
}
}
protected void On$EventName$()
{
On$EventName$(EventArgs.Empty);
}
#endregion
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Keywords>
<Keyword>Event</Keyword>
<Keyword>EventArgs</Keyword>
<Keyword>ASP.NET</Keyword>
<Keyword>Control</Keyword>
<Keyword>WebControl</Keyword>
</Keywords>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Event - Control Args</Title>
<Author>Alan McBee</Author>
<Description>Creates a C# style event property construct and methods for an event WITH parameters, for classes which ARE derived from ASP.NET System.Web.Control</Description>
<HelpUrl>http://www.codecharm.com/Home/tabid/61/EntryId/40/Updated-C-Event-snippets.aspx</HelpUrl>
<Shortcut>eventca</Shortcut>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>System.dll</Assembly>
</Reference>
</References>
<Declarations>
<Literal Editable="true">
<ID>EventName</ID>
<ToolTip>Name of the event</ToolTip>
<Default>Event</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>ParameterName</ID>
<ToolTip>Name of the (first) parameter to the EventArgs-based class constructor</ToolTip>
<Default>parameter</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>PropertyName</ID>
<ToolTip>Name of the (first) property of the EventArgs-based class</ToolTip>
<Default>Property</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>EventCategory</ID>
<ToolTip>Property window category</ToolTip>
<Default>Category</Default>
<Function>
</Function>
</Literal>
<Object Editable="true">
<ID>ParameterType</ID>
<ToolTip>Type of the (first) parameter</ToolTip>
<Default>Object</Default>
<Function>
</Function>
<Type>System.Type</Type>
</Object>
</Declarations>
<Code Language="csharp"><![CDATA[#region $EventName$ Event
private static readonly object c_$EventName$Event = new object();
public class $EventName$EventArgs
: EventArgs
{
public $EventName$EventArgs($ParameterType$ $ParameterName$)
{
$PropertyName$ = $ParameterName$;
}
public $ParameterType$ $PropertyName$
{
get;
set;
}
}
public delegate void $EventName$EventHandler(object sender, $EventName$EventArgs e);
[Category("$EventCategory$")]
public event $EventName$EventHandler $EventName$
{
add { Events.AddHandler($EventName$Event, value); }
remove { Events.RemoveHandler($EventName$Event, value); }
}
protected virtual void On$EventName$($EventName$EventArgs e)
{
$EventName$EventHandler handler = ($EventName$EventHandler)Events[$EventName$Event];
if (null != handler)
{
handler(this, e);
}
}
protected void On$EventName$($ParameterType$ $ParameterName$)
{
$EventName$EventArgs e = new $EventName$EventArgs($ParameterName$);
On$EventName$(e);
}
#endregion
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Keywords>
<Keyword>Event</Keyword>
</Keywords>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Event - Basic</Title>
<Author>Alan McBee</Author>
<Description>Creates a C# style event field construct and methods for an event without parameters, for classes NOT derived from ASP.NET System.Web.Control</Description>
<HelpUrl>http://www.codecharm.com/Home/tabid/61/EntryId/40/Updated-C-Event-snippets.aspx</HelpUrl>
<Shortcut>event</Shortcut>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>System.dll</Assembly>
</Reference>
</References>
<Declarations>
<Literal Editable="true">
<ID>EventName</ID>
<ToolTip>Name of the event</ToolTip>
<Default>Event</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>EventCategory</ID>
<ToolTip>Property window category</ToolTip>
<Default>Category</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[
#region $EventName$ Event
[Category("$EventCategory$")]
public event EventHandler $EventName$;
protected virtual void On$EventName$(EventArgs e)
{
EventHandler handler = $EventName$;
if (null != handler)
{
handler(this, e);
}
}
protected void On$EventName$()
{
On$EventName$(EventArgs.Empty);
}
#endregion
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Keywords>
<Keyword>Event</Keyword>
<Keyword>EventArgs</Keyword>
</Keywords>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Event - Generic</Title>
<Author>Alan McBee</Author>
<Description>Creates a C# style event field construct and methods for an event WITH parameters, for classes NOT derived from ASP.NET System.Web.Control</Description>
<HelpUrl>http://www.codecharm.com/Home/tabid/61/EntryId/40/Updated-C-Event-snippets.aspx</HelpUrl>
<Shortcut>eventg</Shortcut>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>System.dll</Assembly>
</Reference>
</References>
<Declarations>
<Literal Editable="true">
<ID>EventName</ID>
<ToolTip>Name of the event</ToolTip>
<Default>Event</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>ParameterName</ID>
<ToolTip>Name of the (first) parameter to the EventArgs-based class constructor</ToolTip>
<Default>parameter</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>PropertyName</ID>
<ToolTip>Name of the (first) property of the EventArgs-based class</ToolTip>
<Default>Property</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>EventCategory</ID>
<ToolTip>Property window category</ToolTip>
<Default>Category</Default>
<Function>
</Function>
</Literal>
<Object Editable="true">
<ID>ParameterType</ID>
<ToolTip>Name of the (first) property of the EventArgs-based class</ToolTip>
<Default>Object</Default>
<Function>
</Function>
<Type>System.Type</Type>
</Object>
</Declarations>
<Code Language="csharp"><![CDATA[
#region $EventName$ Event
public class $EventName$EventArgs
: EventArgs
{
public $EventName$EventArgs($ParameterType$ $ParameterName$)
{
$PropertyName$ = $ParameterName$;
}
public $ParameterType$ $PropertyName$
{
get;
set;
}
}
[Category("$EventCategory$")]
public event EventHandler<$EventName$EventArgs> $EventName$;
protected virtual void On$EventName$($EventName$EventArgs e)
{
EventHandler<$EventName$EventArgs> handler = $EventName$;
if (null != handler)
{
handler(this, e);
}
}
protected void On$EventName$($ParameterType$ $ParameterName$)
{
$EventName$EventArgs e = new $EventName$EventArgs($ParameterName$);
On$EventName$(e);
}
#endregion
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Lazy-Load Property Getter</Title>
<Description>Creates a C# lazy-load property getter for objects with a default constructor.</Description>
<Author>Alan McBee</Author>
<Shortcut>llp</Shortcut>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>propvar</ID>
<Default>privateVariable</Default>
</Literal>
<Literal>
<ID>access</ID>
<Default>public</Default>
<Type>System.CodeDom.MemberAttributes</Type>
</Literal>
<Literal>
<ID>propname</ID>
<Default>PropertyName</Default>
</Literal>
<Object>
<ID>proptype</ID>
<Default>object</Default>
<Type>System.Type</Type>
</Object>
</Declarations>
<Code Language="CSharp">
<![CDATA[
private $proptype$ _$propvar$;
$access$ $proptype$ $propname$
{
get
{
if (null == _$propvar$)
{
_$propvar$ = new $proptype$();
}
return _$propvar$;
}
}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Create a unit test method for NUnit only</Title>
<Shortcut>utn</Shortcut>
<Description>Code snippet for a unit test with attributes for NUnit.</Description>
<Author>Alan McBee</Author>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>method</ID>
<ToolTip>Unit Test Method Name</ToolTip>
<Default>TestMethod</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
[Test]
public void $method$()
{
}
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Define an attached WPF DependencyProperty</Title>
<Shortcut>propa</Shortcut>
<Description>Code snippet for an attached property using WPF DependencyProperty as the backing store</Description>
<Author>Alan McBee</Author>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>WindowsBase.dll</Assembly>
</Reference>
<Reference>
<Assembly>System</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>System.Windows</Namespace>
</Import>
<Import>
<Namespace>System</Namespace>
</Import>
<Import>
<Namespace>System.Diagnostics</Namespace>
</Import>
</Imports>
<Declarations>
<Literal Editable="true">
<ID>type</ID>
<ToolTip>The type of the property.</ToolTip>
<Default>object</Default>
</Literal>
<Literal Editable="true">
<ID>property</ID>
<ToolTip>The name of the dependency property to register. The name must be unique within the registration namespace of the owner type.</ToolTip>
<Default>Property</Default>
</Literal>
<Literal Editable="false">
<ID>ownerclass</ID>
<ToolTip>The owner type that is registering the dependency property.</ToolTip>
<Default>ClassNamePlaceholder</Default>
<Function>ClassName()</Function>
</Literal>
</Declarations>
<Code Language="csharp" Kind="method decl">
<![CDATA[/// <summary>
/// $property$ WPF DependencyProperty
/// </summary>
public static readonly DependencyProperty $property$Property = DependencyProperty.RegisterAttached("$property$", typeof($type$), typeof($ownerclass$), new UIPropertyMetadata(default($type$)));
/// <summary>
/// $property$ DependencyProperty Wrapper Get Method
/// </summary>
[DebuggerHidden]
public static $type$ Get$property$(DependencyObject obj)
{
// DependencyProperty wrappers are bypassed when setting properties with XAML
return ($type$)obj.GetValue($property$Property);
}
/// <summary>
/// $property$ DependencyProperty Wrapper Set Method
/// </summary>
[DebuggerHidden]
public static void Set$property$(DependencyObject obj, $type$ value)
{
// DependencyProperty wrappers are bypassed when setting properties with XAML
obj.SetValue($property$Property, value);
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Define a WPF DependencyProperty</Title>
<Shortcut>propdp</Shortcut>
<Description>Code snippet for a property using WPF DependencyProperty as the backing store</Description>
<Author>Alan McBee</Author>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>WindowsBase.dll</Assembly>
</Reference>
<Reference>
<Assembly>System</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>System.Windows</Namespace>
</Import>
<Import>
<Namespace>System</Namespace>
</Import>
<Import>
<Namespace>System.Diagnostics</Namespace>
</Import>
</Imports>
<Declarations>
<Literal Editable="true">
<ID>type</ID>
<ToolTip>The type of the property.</ToolTip>
<Default>object</Default>
</Literal>
<Literal Editable="true">
<ID>property</ID>
<ToolTip>The name of the dependency property to register. The name must be unique within the registration namespace of the owner type.</ToolTip>
<Default>Property</Default>
</Literal>
<Literal Editable="true">
<ID>ownerclass</ID>
<ToolTip>The owner type that is registering the dependency property.</ToolTip>
<Default>ClassNamePlaceholder</Default>
<Function>ClassName()</Function>
</Literal>
</Declarations>
<Code Language="csharp" Kind="method decl">
<![CDATA[/// <summary>
/// $property$ WPF DependencyProperty
/// </summary>
public static readonly DependencyProperty $property$Property = DependencyProperty.Register("$property$", typeof($type$), typeof($ownerclass$), new UIPropertyMetadata(default($type$)));
/// <summary>
/// $property$ DependencyProperty Wrapper
/// </summary>
[DebuggerHidden]
public $type$ $property$
{
// DependencyProperty wrappers are bypassed when setting properties with XAML
get { return ($type$)GetValue($property$Property); }
set { SetValue($property$Property, value); }
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Define a read-only WPF DependencyProperty</Title>
<Shortcut>propdpg</Shortcut>
<Description>Code snippet for a read-only property using WPF DependencyProperty as the backing store</Description>
<Author>Alan McBee</Author>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>WindowsBase.dll</Assembly>
</Reference>
<Reference>
<Assembly>System</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>System.Windows</Namespace>
</Import>
<Import>
<Namespace>System</Namespace>
</Import>
<Import>
<Namespace>System.Diagnostics</Namespace>
</Import>
</Imports>
<Declarations>
<Literal Editable="true">
<ID>type</ID>
<ToolTip>The type of the property.</ToolTip>
<Default>object</Default>
</Literal>
<Literal Editable="true">
<ID>property</ID>
<ToolTip>The name of the dependency property to register. The name must be unique within the registration namespace of the owner type.</ToolTip>
<Default>Property</Default>
</Literal>
<Literal Editable="true">
<ID>ownerclass</ID>
<ToolTip>The owner type that is registering the dependency property.</ToolTip>
<Default>ClassNamePlaceholder</Default>
<Function>ClassName()</Function>
</Literal>
</Declarations>
<Code Language="csharp" Kind="method decl">
<![CDATA[/// <summary>
/// $property$ WPF DependencyPropertyKey
/// </summary>
private static readonly DependencyPropertyKey $property$PropertyKey = DependencyProperty.RegisterReadonly("$property$", typeof($type$), typeof($ownerclass$), new UIPropertyMetadata(default($type$)));
/// <summary>
/// $property$ WPF DependencyProperty
/// </summary>
public static readonly DepenedencyProperty $property$Property = $property$PropertyKey.DependencyProperty;
/// <summary>
/// $property$ DependencyProperty Wrapper
/// </summary>
[DebuggerHidden]
public $type$ $property$
{
// DependencyProperty wrappers are bypassed when setting properties with XAML
get { return ($type$)GetValue($property$Property); }
private set { SetValue($property$PropertyKey, value); }
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Author>
Matthias Shapiro (Original),
Nathan Allen-Wagner (Modifications)
</Author>
<HelpUrl>http://blog.alner.net/</HelpUrl>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>
INotifyPropertyChanged Property: Use this to create a
new property INotifyPropertyChanged implementation.
</Title>
<Shortcut>propn</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>publicProperty</ID>
<ToolTip>The name of the private property</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal>
<ID>type</ID>
<ToolTip>
The type of the property
(e.g. string, double, bool, Brush, etc.)
</ToolTip>
<Default>string</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
private $type$ _$publicProperty$;
public $type$ $publicProperty$
{
get{ return _$publicProperty$;}
set
{
if (value != _$publicProperty$)
{
_$publicProperty$ = value;
OnPropertyChanged();
}
}
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Define a bubbling routed event</Title>
<Shortcut>revent</Shortcut>
<Description>Code snippet for a bubbling routed event.</Description>
<Author>Sebastien Lambla</Author>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>event</ID>
<ToolTip>Event Name</ToolTip>
<Default>Event</Default>
</Literal>
<Literal Editable="false">
<ID>ownerclass</ID>
<ToolTip>The owning class of this Property. Typically the class that it is declared in.</ToolTip>
<Default>ClassNamePlaceholder</Default>
<Function>ClassName()</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[public static readonly RoutedEvent $event$Event = EventManager.RegisterRoutedEvent("$event$", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof($ownerclass$));
public event RoutedEventHandler $event$
{
add { AddHandler($event$Event, value); }
remove { RemoveHandler($event$Event, value); }
}
void Raise$event$Event()
{
RoutedEventArgs newEventArgs = new RoutedEventArgs($ownerclass$.$event$Event);
RaiseEvent(newEventArgs);
}
$end$]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Define a bubbling routed event</Title>
<Shortcut>reventpre</Shortcut>
<Description>Code snippet for a bubbling routed event with a preview(?).</Description>
<Author>Sebastien Lambla</Author>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>type</ID>
<ToolTip>Property Type</ToolTip>
<Default>int</Default>
</Literal>
<Literal Editable="true">
<ID>eventName</ID>
<ToolTip>Event Name</ToolTip>
<Default>MyEvent</Default>
</Literal>
<Literal Editable="false">
<ID>ownerclass</ID>
<ToolTip>The owning class of this Property. Typically the class that it is declared in.</ToolTip>
<Default>ClassNamePlaceholder</Default>
<Function>ClassName()</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[public static readonly RoutedEvent Preview$eventName$Event = EventManager.RegisterRoutedEvent("$eventName$", RoutingStrategy.Tunnel, typeof(RoutedEventHandler), typeof($ownerclass$));
public event RoutedEventHandler Preview$eventName$
{
add { AddHandler($eventName$Event, value); }
remove { RemoveHandler($eventName$Event, value); }
}
void RaisePreview$eventName$Event()
{
RoutedEventArgs newEventArgs = new RoutedEventArgs($ownerclass$.Preview$eventName$Event);
RaiseEvent(newEventArgs);
}
$end$]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Singleton</Title>
<Author>Alan McBee</Author>
<Description>Creates C# Singleton pattern</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>sing</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="false">
<ID>classname</ID>
<ToolTip>Class name</ToolTip>
<Default>ClassNamePlaceholder</Default>
<Function>ClassName()</Function>
</Literal>
</Declarations>
<Code Language="csharp" Delimiter="$"><![CDATA[#region Singleton
private readonly static object c_syncLockObject = new object();
private volatile static $classname$ c_singleton;
private $classname$()
{
}
public static $classname$ Default
{
get
{
if (null == c_singleton)
{
lock (c_syncLockObject)
{
if (null == c_singleton)
{
c_singleton = new $classname$();
}
}
}
return c_singleton;
}
}
#endregion
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Create a unit test method for VS Test only</Title>
<Shortcut>utv</Shortcut>
<Description>Code snippet for a unit test with attributes for VS Test.</Description>
<Author>Alan McBee</Author>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>method</ID>
<ToolTip>Unit Test Method Name</ToolTip>
<Default>TestMethod</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
[TestMethod]
public void $method$()
{
}
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>XUnitFact</Title>
<Author>amcbee</Author>
<Description>
</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>aaaf</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>Test</ID>
<ToolTip>Test name</ToolTip>
<Default>Test</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp" Delimiter="$"><![CDATA[[Fact]
public void $Test$()
{
// arrange
// act
// assert
}]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Create a unit test method for both NUnit and VS Test</Title>
<Shortcut>utx</Shortcut>
<Description>Code snippet for a unit test with attributes for both NUnit and VS Test.</Description>
<Author>Alan McBee</Author>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>method</ID>
<ToolTip>Unit Test Method Name</ToolTip>
<Default>TestMethod</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
[NUnit.Framework.Test]
[TestMethod]
public void $method$()
{
}
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>XUnitTheory</Title>
<Author>amcbee</Author>
<Description>
</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>aaat</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>Test</ID>
<ToolTip>Test name</ToolTip>
<Default>Test</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>object</ID>
<ToolTip>Type</ToolTip>
<Default>object</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>value</ID>
<ToolTip>value</ToolTip>
<Default>value</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp" Delimiter="$"><![CDATA[[Theory, AutoData]
public void $Test$($object$ $value$)
{
// arrange
// act
// assert
}]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment