I was in the middle of creating my experiance/article about the snippets subject when I got an email from http://www.codeproject.com/ with this wonderful article.
I've already created some snippets, feel free to use them:
'Decorator-Pattern' snippet (activation: dp_decorator + TAB):
Code Snippet
- xml version="1.0" encoding="utf-8" ?>
- <CodeSnippetsxmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
- <CodeSnippet Format="1.0.0">
- <Header>
- <Title>Decorator DPTitle>
- <Shortcut>dp_decoratorShortcut>
- <Description>Code snippet for decorator design patternDescription>
- <Author>S.OAuthor>
- <SnippetTypes>
- <SnippetType>ExpansionSnippetType>
- SnippetTypes>
- Header>
- <Snippet>
- <Declarations>
- <Literal>
- <ID>ComponentID>
- <ToolTip>Component nameToolTip>
- <Default>ComponentDefault>
- Literal>
- <Literal>
- <ID>DecoratorID>
- <ToolTip>Decorator nameToolTip>
- <Default>DecoratorDefault>
- Literal>
- Declarations>
- <Code Language="csharp">
- // Decorator patern:
- // http://en.wikipedia.org/wiki/Decorator_pattern#Structure
- // http://www.dofactory.com/Patterns/PatternDecorator.aspx
- abstract class $Component$
- {
- public abstract void Operation();
- }
- abstract class $Decorator$ : $Component$
- {
- protected $Component$ _$Component$;
- public void SetComponent($Component$ component)
- {
- this._$Component$ = component;
- }
- public override void Operation()
- {
- if (_$Component$ != null)
- {
- _$Component$.Operation();
- // + [your operation here]
- }
- }
- }
- $end$
- ]]>
- Code>
- Snippet>
- CodeSnippet>
- CodeSnippets>
The 'Event changed property' snippet (eprop + TAB):
Code Snippet
- xml version="1.0" encoding="utf-8" ?>
- <CodeSnippetsxmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
- <CodeSnippet Format="1.0.0">
- <Header>
- <Title>event changed propertyTitle>
- <Shortcut>epropShortcut>
- <Description>Code snippet for eprop...Description>
- <Author>SOAuthor>
- <SnippetTypes>
- <SnippetType>ExpansionSnippetType>
- SnippetTypes>
- Header>
- <Snippet>
- <Declarations>
- <Literal Editable="true">
- <ID>prop_nameID>
- <ToolTip>property nameToolTip>
- <Function>PropName()Function>
- <Default>PropNameDefault>
- Literal>
- <Literal Editable="true">
- <ID>prop_typeID>
- <ToolTip>property typeToolTip>
- <Function>PropType()Function>
- <Default>ObjectDefault>
- Literal>
- Declarations>
- <Code Language="csharp">
- #region $prop_name$
- ///
- /// Occurs when $prop_name$ changes.
- ///
- public event EventHandler $prop_name$Changed;
- ///
- /// Raises the
event. - ///
- /// The
instance containing the event data. - protected virtual void On$prop_name$Changed(EventArgs e)
- {
- if ($prop_name$Changed != null)
- $prop_name$Changed(this, e);
- }
- private $prop_type$ _$prop_name$ = null;$end$
- ///
- /// Gets or sets the type of the region.
- ///
- ///
- /// The type of the region.
- ///
- public $prop_type$ $prop_name$
- {
- get { return _$prop_name$; }
- set
- {
- if (_$prop_name$ != value)
- {
- _$prop_name$ = value;
- On$prop_name$Changed(new EventArgs());
- }
- }
- }
- #endregion
- ]]>
- Code>
- Snippet>
- CodeSnippet>
- CodeSnippets>
And the 'TODO' snippet (TD + TAB), need some polish like auto date/time stamp, priority...:
Code Snippet
- xml version="1.0" encoding="utf-8" ?>
- <CodeSnippetsxmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
- <CodeSnippet Format="1.0.0">
- <Header>
- <Title>TODOTitle>
- <Shortcut>TDShortcut>
- <Description>Code snippet for TODO...Description>
- <Author>SOAuthor>
- <SnippetTypes>
- <SnippetType>ExpansionSnippetType>
- SnippetTypes>
- Header>
- <Snippet>
- <Declarations>
- Declarations>
- <Code Language="csharp">// TODO:P, TimeStamp, S.O: $end$]]>
- Code>
- Snippet>
- CodeSnippet>
- CodeSnippets>
My advice: if you already created a code pattern twice (meaning - you copied and pasted a code and renamed some variables and function/property names), add it to your snippets, you'll need it and it will save time.
REMARK: Please follow the codeproject artical if you wish to install/use them...
REMARK: Please follow the codeproject artical if you wish to install/use them...
No comments:
Post a Comment