<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://davesexton.com/blog/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Snippet Downloads</title><link>http://davesexton.com/blog/files/folders/snippets/default.aspx</link><description>Collection of my personal C# code snippets that you can use when developing your own software.</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.2)</generator><item><title>All Snippets (.zip)</title><link>http://davesexton.com/blog/files/folders/snippets/entry26.aspx</link><pubDate>Mon, 19 Mar 2007 08:30:34 GMT</pubDate><guid isPermaLink="false">5b5c6d2b-d071-4bf8-ac28-4f9cd768b39b:26</guid><dc:creator>Dave Sexton</dc:creator><slash:comments>0</slash:comments><description>&lt;P&gt;&lt;STRONG&gt;My snippets are provided "as is", with no warranty of any kind, either express or implied.&amp;nbsp; Use at your own risk.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This download is a compressed ZIP file that contains all of my C# Code Snippets.&amp;nbsp; Each snippet is&amp;nbsp;available for download separately as well &lt;A href="http://davesexton.com/cs/files/folders/snippets/default.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Alternative Download Method&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If you'd prefer a &lt;STRONG&gt;Visual Studio Content Installer&lt;/STRONG&gt; package (.vsi) instead it's available for download&amp;nbsp;&lt;A class="" href="http://davesexton.com/cs/files/folders/snippets/entry25.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;When you run the .vsi&amp;nbsp;file it&amp;nbsp;will show you all of the components that&amp;nbsp;it contains and allow you to choose where the snippets may be copied so that Visual Studio will find them.&amp;nbsp; You may choose which snippets you'd like as well and each snippet provides a tooltip with its summary.&lt;/P&gt;
&lt;P&gt;For more information on&amp;nbsp;my C# Code Snippets see my blog entry: &lt;A title="Custom C# Code Snippets" href="http://davesexton.com/cs/blogs/blog/archive/2006/12/14/Custom-C_2300_-Code-Snippets.aspx"&gt;Custom C# Code Snippets&lt;/A&gt;.&lt;/P&gt;</description><enclosure url="http://davesexton.com/blog/files/folders/26/download.aspx" length="7844" type="application/x-zip-compressed" /></item><item><title>All Snippets (Installer)</title><link>http://davesexton.com/blog/files/folders/snippets/entry25.aspx</link><pubDate>Mon, 19 Mar 2007 08:26:51 GMT</pubDate><guid isPermaLink="false">5b5c6d2b-d071-4bf8-ac28-4f9cd768b39b:25</guid><dc:creator>Dave Sexton</dc:creator><slash:comments>0</slash:comments><description>&lt;P&gt;&lt;STRONG&gt;My snippets are provided "as is", with no warranty of any kind, either express or implied.&amp;nbsp; Use at your own risk.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This download is a &lt;STRONG&gt;Visual Studio Content Installer&lt;/STRONG&gt; package (.vsi)&amp;nbsp;that contains all of my C# Code Snippets.&amp;nbsp; Each snippet is&amp;nbsp;available for download separately as well &lt;A href="http://davesexton.com/cs/files/folders/snippets/default.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;For more information on&amp;nbsp;my C# Code Snippets see my blog entry: &lt;A title="Custom C# Code Snippets" href="http://davesexton.com/cs/blogs/blog/archive/2006/12/14/Custom-C_2300_-Code-Snippets.aspx"&gt;Custom C# Code Snippets&lt;/A&gt;.&lt;/P&gt;
&lt;H4&gt;How to use the installer file&lt;/H4&gt;
&lt;P&gt;Download the &lt;SPAN id=_ctl0__ctl0_TaskRegion_FileName&gt;&lt;EM&gt;CSharp_Snippets.vsi&lt;/EM&gt; &lt;/SPAN&gt;file to your computer, browse to it using Windows Explorer, and double-click it.&amp;nbsp; The installer will show you all of the components that my .vsi file contains and ask you where you want to&amp;nbsp;copy each snippet after clicking &lt;EM&gt;Next&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Note: Because the file isn't signed with a software publisher's certificate it will prompt you to continue; you must click Yes.&amp;nbsp; &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Installation with the Visual Studio Content Installer&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Start the installation by double-clicking the .vsi file that you downloaded.&lt;/LI&gt;
&lt;LI&gt;Click &lt;EM&gt;Next&lt;/EM&gt; to begin installation.&lt;/LI&gt;
&lt;LI&gt;Click &lt;EM&gt;Yes &lt;/EM&gt;when you are warned that the package isn't signed.&lt;/LI&gt;
&lt;LI&gt;Select all of the snippets in the left-hand pane at once using &lt;EM&gt;Shift&lt;/EM&gt; or &lt;EM&gt;Ctrl,&lt;/EM&gt; or drag the mouse over all of them with the left-mouse button pressed.&lt;/LI&gt;
&lt;LI&gt;Check the item in the right-hand pane labeled &lt;EM&gt;My Code Snippets&lt;/EM&gt;.&amp;nbsp; The tooltip will show you the full path of that directory, usually found at &lt;EM&gt;My Documents\Visual Studio 2005\Code Snippets\Visual C#\My Code Snippets&lt;/EM&gt;.&amp;nbsp;&amp;nbsp;(You can choose the &lt;EM&gt;Visual C#&lt;/EM&gt; directory instead if you'd like; however, the snippets will then&amp;nbsp;be installed in Visual Studio's installation directory instead of the &lt;EM&gt;Visual Studio 2005&lt;/EM&gt; folder under &lt;EM&gt;My Documents&lt;/EM&gt;.&amp;nbsp;&amp;nbsp;If&amp;nbsp;you need to locate them for some reason in the future, you'll probably have an easier time finding them under &lt;EM&gt;My Code Snippets&lt;/EM&gt;.)&lt;/LI&gt;
&lt;LI&gt;Click&amp;nbsp;&lt;EM&gt;Next&lt;/EM&gt; and then&amp;nbsp;&lt;EM&gt;Finish&lt;/EM&gt; to install the snippets. &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;If you'd&amp;nbsp;prefer a plain ZIP version instead&amp;nbsp;I've&amp;nbsp;provided that &lt;A class="" href="http://davesexton.com/cs/files/folders/snippets/entry26.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;</description><enclosure url="http://davesexton.com/blog/files/folders/25/download.aspx" length="8752" type="application/ms-vsi" /></item><item><title>Component Event Member Snippet</title><link>http://davesexton.com/blog/files/folders/snippets/entry24.aspx</link><pubDate>Mon, 19 Mar 2007 08:12:03 GMT</pubDate><guid isPermaLink="false">5b5c6d2b-d071-4bf8-ac28-4f9cd768b39b:24</guid><dc:creator>Dave Sexton</dc:creator><slash:comments>0</slash:comments><description>&lt;P&gt;&lt;STRONG&gt;My snippets are provided "as is", with no warranty of any kind, either express or implied.&amp;nbsp; Use at your own risk.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Creates the canonical event member declaration and corresponding method for invocation for a class that derives from System.ComponentModel.Component.&amp;nbsp; EventHandler is used as the delegate.&amp;nbsp; The code produced by this snippet is thread-safe.&lt;/P&gt;
&lt;P&gt;Shortcut: &lt;EM&gt;eventc&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;For more information on&amp;nbsp;my C# Code Snippets see my blog entry: &lt;A title="Custom C# Code Snippets" href="http://davesexton.com/cs/blogs/blog/archive/2006/12/14/Custom-C_2300_-Code-Snippets.aspx"&gt;Custom C# Code Snippets&lt;/A&gt;.&amp;nbsp; All of my snippets may be downloaded at once &lt;A class="" href="http://davesexton.com/blog/files/folders/snippets/entry25.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Usage&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This snippet is intended to be used as &lt;STRONG&gt;expansion&lt;/STRONG&gt; or &lt;STRONG&gt;surrounds with&lt;/STRONG&gt; from within the body of a class definition. The class must derive, directly or indirectly, from a class with a &lt;CODE&gt;System.ComponentModel.EventHandlerList Events { get; }&lt;/CODE&gt; property defined with accessible scope. Otherwise, the property must be defined in the class itself.&lt;/P&gt;
&lt;P&gt;It's useful for classes that derive from &lt;EM&gt;System.ComponentModel.Component&lt;/EM&gt; or derived types such as the WinForms &lt;EM&gt;Control&lt;/EM&gt; class. The ASP.NET &lt;EM&gt;Control&lt;/EM&gt; class does not derive from &lt;EM&gt;System.ComponentModel.Component&lt;/EM&gt;, however, it provides an &lt;EM&gt;EventHandlerList&lt;/EM&gt; instance via a protected, read-only &lt;EM&gt;Events&lt;/EM&gt; property. Therefore, this snippet is suitable for classes that derive from any FCL component or control.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example Output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The following code illustrates this snippet's output using the default token values: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;private readonly object TextChangedEvent = new object();

/// &amp;lt;summary&amp;gt;
/// Event raised after the &amp;lt;see cref="Text" /&amp;gt;  property value has changed.
/// &amp;lt;/summary&amp;gt;
[Category("Property Changed")]
[Description("Event raised after the Text property value has changed.")]
public event EventHandler TextChanged
{
  add
  {
    lock (TextChangedEvent)
    {
      Events.AddHandler(TextChangedEvent, value);
    }
  }
  remove
  {
    lock (TextChangedEvent)
    {
      Events.RemoveHandler(TextChangedEvent, value);
    }
  }
}

/// &amp;lt;summary&amp;gt;
/// Raises the &amp;lt;see cref="TextChanged" /&amp;gt; event.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="e"&amp;gt;&amp;lt;see cref="EventArgs" /&amp;gt; object that provides the arguments for the event.&amp;lt;/param&amp;gt;
protected virtual void OnTextChanged(EventArgs e)
{
  EventHandler handler = null;

  lock (TextChangedEvent)
  {
    handler = (EventHandler) Events[TextChangedEvent];
  }

  if (handler != null)
    handler(this, e);
}&lt;CODE&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description><enclosure url="http://davesexton.com/blog/files/folders/24/download.aspx" length="2633" type="application/xml" /></item><item><title>Custom EventArgs Snippet</title><link>http://davesexton.com/blog/files/folders/snippets/entry23.aspx</link><pubDate>Mon, 19 Mar 2007 08:11:22 GMT</pubDate><guid isPermaLink="false">5b5c6d2b-d071-4bf8-ac28-4f9cd768b39b:23</guid><dc:creator>Dave Sexton</dc:creator><slash:comments>0</slash:comments><description>&lt;P&gt;&lt;STRONG&gt;My snippets are provided "as is", with no warranty of any kind, either express or implied.&amp;nbsp; Use at your own risk.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Creates the definition for a class that inherits from EventArgs.&lt;/P&gt;
&lt;P&gt;Shortcut: &lt;EM&gt;eventargs&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;For more information on&amp;nbsp;my C# Code Snippets see my blog entry: &lt;A title="Custom C# Code Snippets" href="http://davesexton.com/cs/blogs/blog/archive/2006/12/14/Custom-C_2300_-Code-Snippets.aspx"&gt;Custom C# Code Snippets&lt;/A&gt;.&amp;nbsp; All of my snippets may be downloaded at once &lt;A class="" href="http://davesexton.com/blog/files/folders/snippets/entry25.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Usage&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This snippet is intended to be used as expansion only.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example Output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The following code illustrates this snippet's output: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;/// &amp;lt;summary&amp;gt;
/// Provides arguments for an event.
/// &amp;lt;/summary&amp;gt;
[Serializable]
public class CustomEventArgs : EventArgs
{
  public new static readonly CustomEventArgs Empty = new CustomEventArgs();

  #region Public Properties
  #endregion

  #region Private / Protected
  #endregion

  #region Constructors
  /// &amp;lt;summary&amp;gt;
  /// Constructs a new instance of the &amp;lt;see cref="CustomEventArgs" /&amp;gt; class.
  /// &amp;lt;/summary&amp;gt;
  public CustomEventArgs(|)  &amp;lt; {text cursor goes here}
  {
  }
  #endregion
}&lt;/CODE&gt;&lt;/PRE&gt;</description><enclosure url="http://davesexton.com/blog/files/folders/23/download.aspx" length="1499" type="application/xml" /></item><item><title>Designer Layout Regions Snippet</title><link>http://davesexton.com/blog/files/folders/snippets/entry22.aspx</link><pubDate>Mon, 19 Mar 2007 08:10:46 GMT</pubDate><guid isPermaLink="false">5b5c6d2b-d071-4bf8-ac28-4f9cd768b39b:22</guid><dc:creator>Dave Sexton</dc:creator><slash:comments>0</slash:comments><description>&lt;P&gt;&lt;STRONG&gt;My snippets are provided "as is", with no warranty of any kind, either express or implied.&amp;nbsp; Use at your own risk.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Creates several #region blocks for the placement of specific code elements from within the body of a class definition created by a designer.&lt;/P&gt;
&lt;P&gt;Shortcut: &lt;EM&gt;layoutd&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;For more information on&amp;nbsp;my C# Code Snippets see my blog entry: &lt;A title="Custom C# Code Snippets" href="http://davesexton.com/cs/blogs/blog/archive/2006/12/14/Custom-C_2300_-Code-Snippets.aspx"&gt;Custom C# Code Snippets&lt;/A&gt;.&amp;nbsp; All of my snippets may be downloaded at once &lt;A class="" href="http://davesexton.com/blog/files/folders/snippets/entry25.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Usage&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This snippet is intended to be used as &lt;STRONG&gt;expansion&lt;/STRONG&gt; or &lt;STRONG&gt;surrounds with&lt;/STRONG&gt; from within the body of a class, struct or interface definition. Using this snippet for a struct or interface requires manual deletion of some of the &lt;EM&gt;regions&lt;/EM&gt; that do not apply. The same goes for &lt;EM&gt;regions&lt;/EM&gt; that do not apply to a particular class definition.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example Output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The following code illustrates this snippet's output when it's executed for expansion from within the body of the Person class: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;class Person
{
  #region Public Properties
  #endregion

  #region Private / Protected
  | {text cursor goes here}
  #endregion

  #region Constructors
  /// &amp;lt;summary&amp;gt;
  /// Constructs a new instance of the &amp;lt;see cref="Person" /&amp;gt; class.
  /// &amp;lt;/summary&amp;gt;
  public Person()
  {
    InitializeComponent();
  }
  #endregion

  #region Methods
  {surrounds selection here}
  #endregion

  #region Events
  #endregion

  #region Event Handlers
  #endregion

  #region Nested
  #endregion
}&lt;/CODE&gt;&lt;/PRE&gt;</description><enclosure url="http://davesexton.com/blog/files/folders/22/download.aspx" length="1353" type="application/xml" /></item><item><title>Dispose Method Override Snippet</title><link>http://davesexton.com/blog/files/folders/snippets/entry21.aspx</link><pubDate>Mon, 19 Mar 2007 08:10:00 GMT</pubDate><guid isPermaLink="false">5b5c6d2b-d071-4bf8-ac28-4f9cd768b39b:21</guid><dc:creator>Dave Sexton</dc:creator><slash:comments>0</slash:comments><description>&lt;P&gt;&lt;STRONG&gt;My snippets are provided "as is", with no warranty of any kind, either express or implied.&amp;nbsp; Use at your own risk.&lt;/STRONG&gt;&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;Creates the canonical Dispose method override code for types that ultimately derive from the System.ComponentModel.Component class.&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;Shortcut: &lt;EM&gt;disposec&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;For more information on&amp;nbsp;my C# Code Snippets see my blog entry: &lt;A title="Custom C# Code Snippets" href="http://davesexton.com/cs/blogs/blog/archive/2006/12/14/Custom-C_2300_-Code-Snippets.aspx"&gt;Custom C# Code Snippets&lt;/A&gt;.&amp;nbsp; All of my snippets may be downloaded at once &lt;A class="" href="http://davesexton.com/blog/files/folders/snippets/entry25.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Usage&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This snippet is intended to be used as expansion only from within the body of a class definition. The class must derive, directly or indirectly, from a class with a &lt;CODE&gt;protected virtual void Dispose(bool disposing)&lt;/CODE&gt; method that is not sealed.&lt;/P&gt;
&lt;P&gt;This snippet is useful for classes that derive from &lt;EM&gt;System.ComponentModel.Component&lt;/EM&gt; or derived types such as WinForms Controls. This snippet is not suitable for classes that derive from the ASP.NET &lt;EM&gt;Control&lt;/EM&gt; class.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example Output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The following code illustrates this snippet's output when it's executed for &lt;STRONG&gt;expansion&lt;/STRONG&gt; from within the body of the &lt;CODE&gt;Person&lt;/CODE&gt; class: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;class Person : Component
{
  /// &amp;lt;summary&amp;gt;
  /// Releases the unmanaged resources used by an instance of the &amp;lt;see cref="Person" /&amp;gt; class 
  /// and optionally releases the managed resources.
  /// &amp;lt;/summary&amp;gt;
  /// &amp;lt;param name="disposing"&amp;gt;&amp;lt;strong&amp;gt;true&amp;lt;/strong&amp;gt; to release both managed and 
  /// unmanaged resources; &amp;lt;strong&amp;gt;false&amp;lt;/strong&amp;gt; to release only unmanaged resources.&amp;lt;/param&amp;gt;
  protected override void Dispose(bool disposing)
  {
    try
    {
      if (disposing)
      {
        | {text cursor goes here}
      }
    }
    finally
    {
      base.Dispose(disposing);
    }
  }
}&lt;/CODE&gt;&lt;/PRE&gt;</description><enclosure url="http://davesexton.com/blog/files/folders/21/download.aspx" length="1323" type="application/xml" /></item><item><title>Event Member Snippet</title><link>http://davesexton.com/blog/files/folders/snippets/entry20.aspx</link><pubDate>Mon, 19 Mar 2007 08:09:12 GMT</pubDate><guid isPermaLink="false">5b5c6d2b-d071-4bf8-ac28-4f9cd768b39b:20</guid><dc:creator>Dave Sexton</dc:creator><slash:comments>0</slash:comments><description>&lt;P&gt;&lt;STRONG&gt;My snippets are provided "as is", with no warranty of any kind, either express or implied.&amp;nbsp; Use at your own risk.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Creates the canonical event member declaration and corresponding method for invocation.&amp;nbsp; EventHandler is used as the delegate.&amp;nbsp; The code produced by this snippet is thread-safe.&lt;/P&gt;
&lt;P&gt;Shortcut: &lt;EM&gt;event&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;For more information on&amp;nbsp;my C# Code Snippets see my blog entry: &lt;A title="Custom C# Code Snippets" href="http://davesexton.com/cs/blogs/blog/archive/2006/12/14/Custom-C_2300_-Code-Snippets.aspx"&gt;Custom C# Code Snippets&lt;/A&gt;.&amp;nbsp; All of my snippets may be downloaded at once &lt;A class="" href="http://davesexton.com/blog/files/folders/snippets/entry25.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Usage&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This snippet is intended to be used as &lt;STRONG&gt;expansion&lt;/STRONG&gt; or &lt;STRONG&gt;surrounds with&lt;/STRONG&gt; from within the body of a class definition.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example Output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The following code illustrates this snippet's output using the default token values: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;private readonly object TextChangedEventLock = new object();
private EventHandler TextChangedEvent;

/// &amp;lt;summary&amp;gt;
/// Event raised after the &amp;lt;see cref="Text" /&amp;gt;  property value has changed.
/// &amp;lt;/summary&amp;gt;
public event EventHandler TextChanged
{
  add
  {
    lock (TextChangedEventLock)
    {
      TextChangedEvent += value;
    }
  }
  remove
  {
    lock (TextChangedEventLock)
    {
      TextChangedEvent -= value;
    }
  }
}

/// &amp;lt;summary&amp;gt;
/// Raises the &amp;lt;see cref="TextChanged" /&amp;gt; event.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="e"&amp;gt;&amp;lt;see cref="EventArgs" /&amp;gt; object that provides the arguments for the event.&amp;lt;/param&amp;gt;
protected virtual void OnTextChanged(EventArgs e)
{
  EventHandler handler = null;

  lock (TextChangedEventLock)
  {
    handler = TextChangedEvent;

    if (handler == null)
      return;
  }

  handler(this, e);
}&lt;CODE&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description><enclosure url="http://davesexton.com/blog/files/folders/20/download.aspx" length="2381" type="application/xml" /></item><item><title>Generic Component Event Member Snippet</title><link>http://davesexton.com/blog/files/folders/snippets/entry19.aspx</link><pubDate>Mon, 19 Mar 2007 08:08:24 GMT</pubDate><guid isPermaLink="false">5b5c6d2b-d071-4bf8-ac28-4f9cd768b39b:19</guid><dc:creator>Dave Sexton</dc:creator><slash:comments>0</slash:comments><description>&lt;P&gt;&lt;STRONG&gt;My snippets are provided "as is", with no warranty of any kind, either express or implied.&amp;nbsp; Use at your own risk.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Creates the canonical event member declaration and corresponding method for invocation for a class that derives from System.ComponentModel.Component. EventHandler&amp;lt;TEventArgs&amp;gt; is used as the delegate and TEventArgs has been tokenized. The code produced by this snippet is thread-safe.&lt;/P&gt;
&lt;P&gt;Shortcut: &lt;EM&gt;eventcg&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;For more information on&amp;nbsp;my C# Code Snippets see my blog entry: &lt;A title="Custom C# Code Snippets" href="http://davesexton.com/cs/blogs/blog/archive/2006/12/14/Custom-C_2300_-Code-Snippets.aspx"&gt;Custom C# Code Snippets&lt;/A&gt;.&amp;nbsp; All of my snippets may be downloaded at once &lt;A class="" href="http://davesexton.com/blog/files/folders/snippets/entry25.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Usage&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This snippet is intended to be used as &lt;STRONG&gt;expansion&lt;/STRONG&gt; or &lt;STRONG&gt;surrounds with&lt;/STRONG&gt; from within the body of a class definition. The class must derive, directly or indirectly, from a class with a &lt;CODE&gt;System.ComponentModel.EventHandlerList Events { get; }&lt;/CODE&gt; property defined with accessible scope. Otherwise, the property must be defined in the class itself.&lt;/P&gt;
&lt;P&gt;It's useful for classes that derive from &lt;EM&gt;System.ComponentModel.Component&lt;/EM&gt; or derived types such as the WinForms &lt;EM&gt;Control&lt;/EM&gt; class. The ASP.NET &lt;EM&gt;Control&lt;/EM&gt; class does not derive from &lt;EM&gt;System.ComponentModel.Component&lt;/EM&gt;, however, it provides an &lt;EM&gt;EventHandlerList&lt;/EM&gt; instance via a protected, read-only &lt;EM&gt;Events&lt;/EM&gt; property. Therefore, this snippet is suitable for classes that derive from any FCL component or control.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example Output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The following code illustrates this snippet's output using the default token values: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;private readonly object TextChangedEvent = new object();

/// &amp;lt;summary&amp;gt;
/// Event raised after the &amp;lt;see cref="Text" /&amp;gt;  property value has changed.
/// &amp;lt;/summary&amp;gt;
[Category("Property Changed")]
[Description("Event raised after the Text property value has changed.")]
public event EventHandler&amp;lt;EventArgs&amp;gt; TextChanged
{
  add
  {
    lock (TextChangedEvent)
    {
      Events.AddHandler(TextChangedEvent, value);
    }
  }
  remove
  {
    lock (TextChangedEvent)
    {
      Events.RemoveHandler(TextChangedEvent, value);
    }
  }
}

/// &amp;lt;summary&amp;gt;
/// Raises the &amp;lt;see cref="TextChanged" /&amp;gt; event.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="e"&amp;gt;&amp;lt;see cref="EventArgs" /&amp;gt; object that provides the arguments for the event.&amp;lt;/param&amp;gt;
protected virtual void OnTextChanged(EventArgs e)
{
  EventHandler&amp;lt;EventArgs&amp;gt; handler = null;

  lock (TextChangedEvent)
  {
    handler = (EventHandler&amp;lt;EventArgs&amp;gt;) Events[TextChangedEvent];
  }

  if (handler != null)
    handler(this, e);
}&lt;/CODE&gt;&lt;/PRE&gt;</description><enclosure url="http://davesexton.com/blog/files/folders/19/download.aspx" length="2582" type="application/xml" /></item><item><title>Generic Event Member Snippet</title><link>http://davesexton.com/blog/files/folders/snippets/entry17.aspx</link><pubDate>Mon, 19 Mar 2007 08:06:06 GMT</pubDate><guid isPermaLink="false">5b5c6d2b-d071-4bf8-ac28-4f9cd768b39b:17</guid><dc:creator>Dave Sexton</dc:creator><slash:comments>0</slash:comments><description>&lt;P&gt;&lt;STRONG&gt;My snippets are provided "as is", with no warranty of any kind, either express or implied.&amp;nbsp; Use at your own risk.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Creates the canonical event member declaration and corresponding method for invocation. EventHandler&amp;lt;TEventArgs&amp;gt; is used as the delegate and TEventArgs has been tokenized. The code produced by this snippet is thread-safe.&lt;/P&gt;
&lt;P&gt;Shortcut: &lt;EM&gt;eventg&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;For more information on&amp;nbsp;my C# Code Snippets see my blog entry: &lt;A title="Custom C# Code Snippets" href="http://davesexton.com/cs/blogs/blog/archive/2006/12/14/Custom-C_2300_-Code-Snippets.aspx"&gt;Custom C# Code Snippets&lt;/A&gt;.&amp;nbsp; All of my snippets may be downloaded at once &lt;A class="" href="http://davesexton.com/blog/files/folders/snippets/entry25.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Usage&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This snippet is intended to be used as &lt;STRONG&gt;expansion&lt;/STRONG&gt; or &lt;STRONG&gt;surrounds with&lt;/STRONG&gt; from within the body of a class definition.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example Output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The following code illustrates this snippet's output using the default token values: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;private readonly object TextChangedEventLock = new object();
private EventHandler&amp;lt;EventArgs&amp;gt; TextChangedEvent;

/// &amp;lt;summary&amp;gt;
/// Event raised after the &amp;lt;see cref="Text" /&amp;gt;  property value has changed.
/// &amp;lt;/summary&amp;gt;
public event EventHandler&amp;lt;EventArgs&amp;gt; TextChanged
{
  add
  {
    lock (TextChangedEventLock)
    {
      TextChangedEvent += value;
    }
  }
  remove
  {
    lock (TextChangedEventLock)
    {
      TextChangedEvent -= value;
    }
  }
}

/// &amp;lt;summary&amp;gt;
/// Raises the &amp;lt;see cref="TextChanged" /&amp;gt; event.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="e"&amp;gt;&amp;lt;see cref="EventArgs" /&amp;gt; object that provides the arguments for the event.&amp;lt;/param&amp;gt;
protected virtual void OnTextChanged(EventArgs e)
{
  EventHandler&amp;lt;EventArgs&amp;gt; handler = null;

  lock (TextChangedEventLock)
  {
    handler = TextChangedEvent;

    if (handler == null)
      return;
  }

  handler(this, e);
}&lt;CODE&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description><enclosure url="http://davesexton.com/blog/files/folders/17/download.aspx" length="2331" type="application/xml" /></item><item><title>IDisposable Implementation Snippet</title><link>http://davesexton.com/blog/files/folders/snippets/entry16.aspx</link><pubDate>Mon, 19 Mar 2007 08:05:16 GMT</pubDate><guid isPermaLink="false">5b5c6d2b-d071-4bf8-ac28-4f9cd768b39b:16</guid><dc:creator>Dave Sexton</dc:creator><slash:comments>0</slash:comments><description>&lt;P&gt;&lt;STRONG&gt;My snippets are provided "as is", with no warranty of any kind, either express or implied.&amp;nbsp; Use at your own risk.&lt;/STRONG&gt;&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;Creates the canonical IDisposable implementation.&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;Shortcut: &lt;EM&gt;disposable&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;For more information on&amp;nbsp;my C# Code Snippets see my blog entry: &lt;A title="Custom C# Code Snippets" href="http://davesexton.com/cs/blogs/blog/archive/2006/12/14/Custom-C_2300_-Code-Snippets.aspx"&gt;Custom C# Code Snippets&lt;/A&gt;.&amp;nbsp; All of my snippets may be downloaded at once &lt;A class="" href="http://davesexton.com/blog/files/folders/snippets/entry25.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Usage&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This snippet is intended to be used as expansion only from within the body of a class definition. The class shouldn't derive, directly or indirectly, from a class with a &lt;CODE&gt;protected virtual void Dispose(bool disposing)&lt;/CODE&gt; method. This snippet should be used on a class that implements IDisposable.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example Output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The following code illustrates this snippet's output when it's executed for &lt;STRONG&gt;expansion&lt;/STRONG&gt; from within the body of the &lt;CODE&gt;Person&lt;/CODE&gt; class: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;class Person : IDisposable
{
  /// &amp;lt;summary&amp;gt;
  /// Releases all resources used by an instance of the &amp;lt;see cref="Person" /&amp;gt; class.
  /// &amp;lt;/summary&amp;gt;
  /// &amp;lt;remarks&amp;gt;
  /// This method calls the virtual &amp;lt;see cref="Dispose(bool)" /&amp;gt; method, 
  /// passing in &amp;lt;strong&amp;gt;true&amp;lt;/strong&amp;gt;, and then suppresses 
  /// finalization of the instance.
  /// &amp;lt;/remarks&amp;gt;
  public void Dispose()
  {
    Dispose(true);
    GC.SuppressFinalize(this);
  }

  /// &amp;lt;summary&amp;gt;
  /// Releases unmanaged resources before an instance of the &amp;lt;see cref="Person" /&amp;gt; 
  /// class is reclaimed by garbage collection.
  /// &amp;lt;/summary&amp;gt;
  /// &amp;lt;remarks&amp;gt;
  /// This method releases unmanaged resources by calling the virtual &amp;lt;see cref="Dispose(bool)" /&amp;gt; 
  /// method, passing in &amp;lt;strong&amp;gt;false&amp;lt;/strong&amp;gt;.
  /// &amp;lt;/remarks&amp;gt;
  ~Person()
  {
    Dispose(false);
  }

  /// &amp;lt;summary&amp;gt;
  /// Releases the unmanaged resources used by an instance of the &amp;lt;see cref="Person" /&amp;gt; 
  /// class and optionally releases the managed resources.
  /// &amp;lt;/summary&amp;gt;
  /// &amp;lt;param name="disposing"&amp;gt;&amp;lt;strong&amp;gt;true&amp;lt;/strong&amp;gt; to release both managed 
  /// and unmanaged resources; &amp;lt;strong&amp;gt;false&amp;lt;/strong&amp;gt; to release only unmanaged resources.&amp;lt;/param&amp;gt;
  protected virtual void Dispose(bool disposing)
  {
    | {text cursor goes here}
  }
}&lt;/CODE&gt;&lt;/PRE&gt;</description><enclosure url="http://davesexton.com/blog/files/folders/16/download.aspx" length="1935" type="application/xml" /></item><item><title>Layout Regions Snippet</title><link>http://davesexton.com/blog/files/folders/snippets/entry15.aspx</link><pubDate>Mon, 19 Mar 2007 08:03:48 GMT</pubDate><guid isPermaLink="false">5b5c6d2b-d071-4bf8-ac28-4f9cd768b39b:15</guid><dc:creator>Dave Sexton</dc:creator><slash:comments>0</slash:comments><description>&lt;P&gt;&lt;STRONG&gt;My snippets are provided "as is", with no warranty of any kind, either express or implied.&amp;nbsp; Use at your own risk.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Creates several #region blocks for the placement of specific code elements from within the body of a class definition.&lt;/P&gt;
&lt;P&gt;Shortcut: &lt;EM&gt;layout&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;For more information on&amp;nbsp;my C# Code Snippets see my blog entry: &lt;A title="Custom C# Code Snippets" href="http://davesexton.com/cs/blogs/blog/archive/2006/12/14/Custom-C_2300_-Code-Snippets.aspx"&gt;Custom C# Code Snippets&lt;/A&gt;.&amp;nbsp; All of my snippets may be downloaded at once &lt;A class="" href="http://davesexton.com/blog/files/folders/snippets/entry25.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Usage&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This snippet is intended to be used as &lt;STRONG&gt;expansion&lt;/STRONG&gt; or &lt;STRONG&gt;surrounds with&lt;/STRONG&gt; from within the body of a class, struct or interface definition. Using this snippet for a struct or interface requires manual deletion of some of the &lt;EM&gt;regions&lt;/EM&gt; that do not apply. The same goes for &lt;EM&gt;regions&lt;/EM&gt; that do not apply to a particular class definition.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example Output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The following code illustrates this snippet's output when it's executed for expansion from within the body of the Person class: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;public class Person
{
  #region Public Properties
  #endregion

  #region Private / Protected
  #endregion

  #region Constructors
  /// &amp;lt;summary&amp;gt;
  /// Constructs a new instance of the &amp;lt;see cref="Person" /&amp;gt; class.
  /// &amp;lt;/summary&amp;gt;
  public Person(|)   &amp;lt; {text cursor goes here}
  {
  }
  #endregion

  #region Methods
  {surrounds selection here}
  #endregion

  #region Events
  #endregion

  #region Event Handlers
  #endregion

  #region Nested
  #endregion
}&lt;/CODE&gt;&lt;/PRE&gt;</description><enclosure url="http://davesexton.com/blog/files/folders/15/download.aspx" length="1288" type="application/xml" /></item></channel></rss>