Snippet VS2010

1 post / 0 new
MasterSleepy
Snippet VS2010

Salut à tous,

Etant en plein développement en Silverlight, je suis amené à faire pas mal de Dependency Properties.
C'est assez verbeux mais c'est indispensable.
Grâce à Visual Studio 2010 et les snippets, ça devient un peu moins verbeux.

Voici les deux que j'utilise le plus en ce moment, la base vient d'une snippet trouver sur le Net, merci à Shawn Wildermuth pour la base.
Je l'ai modifié afin de la Documentation soit correct et le code passe StyleCop sans problème.
Pour Stylecop, certaines règles ont été désactivé dont notamment "ElementsMustAppearInTheCorrectOrder".

Voici la première :
La dependencyProperty avec définition de la méthode OnChange





Define a Silverlight DependencyProperty
sldp
Code snippet for a property using DependencyProperty as the backing store
Shawn Wildermuth

Expansion





type
Property Type
int


property
Property Name
MyProperty


ownerclass
The owning class of this Property. Typically the class that it is declared in.
ownerclass


defaultvalue
The default value for this property.
0



///
/// Gets or sets $property$ value.
///

public $type$ $property$
{
get { return ($type$)GetValue($property$Property); }
set { SetValue($property$Property, value); }
}

///


/// Using a DependencyProperty as the backing store for $property$.
/// This enables animation, styling, binding, etc...
///

public static readonly DependencyProperty $property$Property =
DependencyProperty.Register(
"$property$",
typeof($type$),
typeof($ownerclass$),
new PropertyMetadata($defaultvalue$,new PropertyChangedCallback(On$property$Changed)));

///


/// Event launched when property are changed.
///

///
Sending dependency ///
Dependency event parameters. static void On$property$Changed(object sender, DependencyPropertyChangedEventArgs args)
{
// Get reference to self
$ownerclass$ source = ($ownerclass$)sender;

// Add Handling Code
$type$ newValue = ($type$)args.NewValue;
}
$end$]]>








La DependencyProperty sans la méthode





Define a Silverlight DependencyProperty
sldpwo
Code snippet for a property using DependencyProperty as the backing store without event handler
Michel Van hees

Expansion





type
Property Type
int


property
Property Name
MyProperty


ownerclass
The owning class of this Property. Typically the class that it is declared in.
ownerclass


defaultvalue
The default value for this property.
0



///
/// Gets or sets $property$ value.
///

public $type$ $property$
{
get { return ($type$)GetValue($property$Property); }
set { SetValue($property$Property, value); }
}

///


/// Using a DependencyProperty as the backing store for $property$.
/// This enables animation, styling, binding, etc...
///

public static readonly DependencyProperty $property$Property =
DependencyProperty.Register(
"$property$",
typeof($type$),
typeof($ownerclass$),
new PropertyMetadata($defaultvalue$));
$end$]]>








A+
MasterSleepy.

Migration writed for MasterSleepy