UPDATE 1 : Pour des raisons que je ne détaillerai pas ici, certaines snippets ne référençait pas “http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet” comme xmlns. Le code et le zip est màj avec le “bon” xmlns.
Voici une série de code snippet que je me propose de partager avec vous. Elles sont souvent simples et certaines peuvent sembler un peu outdated, mais comme souvent, le developpement de snippet passe après la documentation et le nettoyage du clavier (vive les sandwich “croustillants” 😉 ). J’ai dev ces snippets au passage à VS2010 et leur migration vers VS2012 s’est déroulée avec succès, j’espère qu’elles vous seront toutes aussi utiles qu’à moi 🙂 La première c’est une snippet de Dprop pour WPF, une configProperty et les 3 autres sont des 3 styles de NotifPropChange dépendant de la version et du contexte d’utilisation. Je reviendrai certainement dans les jours qui suivent avec d’autres.
Dependency Property
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>dprop</Title> <Shortcut>dprop</Shortcut> <Description>Code snippet for dependecy property</Description> <Author>Emmanuel Istace</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>name</ID> <ToolTip>Property name</ToolTip> <Default>Property</Default> </Literal> <Literal> <ID>type</ID> <ToolTip>Property Type</ToolTip> <Default>object</Default> </Literal> <Literal Editable="false"> <ID>classname</ID> <ToolTip>Class name</ToolTip> <Function>ClassName()</Function> <Default>ClassNamePlaceholder</Default> </Literal> </Declarations> <Code Language="csharp"> <![CDATA[ public static readonly DependencyProperty $name$Property = DependencyProperty.Register("$name$", typeof($type$), typeof($classname$)); public $type$ $name$ { get { return ($type$)GetValue($name$Property); } set { SetValue($name$Property, value); } } $end$ ]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>
Configuration Property
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>configprop</Title> <Shortcut>configprop</Shortcut> <Description>Add a configuration property</Description> <Author>Emmanuel Istace</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>Name</ID> <ToolTip>Property Name</ToolTip> <Default>MyProperty</Default> </Literal> <Literal> <ID>type</ID> <ToolTip>Property Type</ToolTip> <Default>string</Default> </Literal> </Declarations> <Code Language="csharp"> <![CDATA[ [ConfigurationProperty("$Name$", IsRequired = true)] public $type$ $Name$ { get { return ($type$)this["$Name$"]; } set { this["$Name$"] = value; } } $end$ ]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>
INotifyPropertyChanged simple implementation
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>nchangeimpl</Title> <Shortcut>nchangeimpl</Shortcut> <Description>Code snippet for INotifyPropertyChanged Simple implementation</Description> <Author>Emmanuel Istace</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Code Language="csharp"> <![CDATA[ #region INotifyPropertyChanged Implementation public event PropertyChangedEventHandler PropertyChanged; protected void NotifyPropertyChanged(string sProp) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(sProp)); } } #endregion]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>
Property Changed Event raising
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>nprop</Title> <Shortcut>nprop</Shortcut> <Description>Code snippet for property with property change event raised</Description> <Author>Istace Emmanuel</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>type</ID> <ToolTip>Type exposed by the dependency property</ToolTip> <Default>object</Default> </Literal> <Literal> <ID>name</ID> <ToolTip>Name of the dependency property</ToolTip> <Default>dprop</Default> </Literal> </Declarations> <Code Language="csharp"> <![CDATA[ #region $name$ property private $type$ _$name$ { get; set; } public $type$ $name$ { get { return _$name$; } set { if(value != _$name$) { _$name$ = value; NotifyPropertyChanged("$name$"); } } } #endregion $end$ ]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>
MVVM Property Changed event raising
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>mvvmlightprop</Title> <Shortcut>mvvmlightprop</Shortcut> <Description>Code snippet for MVVM view model property with property change event raised</Description> <Author>Istace Emmanuel</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>type</ID> <ToolTip>Type exposed by the dependency property</ToolTip> <Default>object</Default> </Literal> <Literal> <ID>name</ID> <ToolTip>Name of the dependency property</ToolTip> <Default>dprop</Default> </Literal> </Declarations> <Code Language="csharp"> <![CDATA[ #region $name$ property private $type$ _$name$ { get; set; } public $type$ $name$ { get { return _$name$; } set { if(value != _$name$) { $type$ oldValue = _$name$; _$name$ = value; RaisePropertyChanged<$type$>("$name$", oldValue, value, false); } } } #endregion $end$ ]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>
I constantly spent my half an hour to read this webpage’s articles or reviews everyday along with a cup of coffee.
Hi there i am kavin, its my first time to commenting anyplace, when i read
this article i thought i could also create comment due to this brilliant piece of writing.
Thanks in favor of sharing such a pleasant opinion, article is pleasant, thats why i have read it fully
fantastic publish, very informative. I wonder why the opposite specialists
of this sector don’t notice this. You must proceed your writing. I am sure, you have a great readers’ base already!
Link exchange is nothing else however it is simply placing the other person’s web site link on your page at suitable place and other person will also do similar in favor of you.
Pretty section of content. I just stumbled upon your blog and in accession capital to assert that I acquire actually enjoyed account your blog posts.
Any way I’ll be subscribing to your feeds and even I achievement you access consistently rapidly.
Wow, this post is good, my sister is analyzing such things, so I am going to convey her.
What a material of un-ambiguity and preserveness of precious knowledge concerning unpredicted feelings.
Hi, its fastidious article on the topic of media print, we all know media is a great source
of data.
So today, I wish to look at five terrific needs to buy web hosting instead of going the 100 % totally free route.
Many Host – Gator reviews on client aid are remarkable. Also, complimentary hosts could limit the content you place on your website.