image

Buenas,

again ReSharper comes to my and hours and hours of unnecessary work, avoids me this time by taking advantage of the widespread ability to generate templates.

If you use much Visual Studio, I assume that you know that if you write "prop" and press the TAB key twice, then the code snippet that comes by default with the IDE create you a template of an auto-implemented property.

image

This is enough in most cases, but when come the friends of the paint and color, because you have to start working with Dinamyc Properties (I think that they are named) where your class must implement the INotifyPropertyChanged interface and then shoot the notification on the set of the property.

We are going a way of implementing a property Name of this type would be something like.

   1: #region Name

   2: [XmlIgnore] public const string NamePropertyName = "Name";

   3: [XmlIgnore] private string _name;

   4: public string Name

   5: {

   6:     get { return _name; }

   7:     set

   8:     {

   9:         _name = value;

  10:         RaisePropertyChanged(NamePropertyName);

  11:     }

  12: }

  13: #endregion

The problem comes when you have to go creating properties of this type in a quick way and you passes what happens to my Friday: you are tired (this serves as an excuse for not thinking a bit more).

But luckily, ReSharper comes with his edition of extended templates and allows you to get you up the problem as if nothing.

The first thing is to access the panel "Explorer Templates" of ReSharper, using the "ReSharper // Templates Explorer" menu. In it we will see the list of templates with which we can work.

image

For the case said earlier, I’ve created a new template called PropNot with the following text within the same

   1: #region $Name$

   2: [XmlIgnore]

   3: public const string $Name$PropertyName = "$Name$";

   4: [XmlIgnore]

   5: private $type$ _$NameLower$;

   6: public $type$ $Name$

   7: {

   8:     get { return _$NameLower$; }

   9:     set

  10:     {

  11:         _$NameLower$ = value;

  12:         RaisePropertyChanged($Name$PropertyName);

  13:     }

  14: }

  15: #endregion

As you can see, variables identified with the sign are implemented within the same $$ and then each of these variables has a special behavior.

-The variable Name $$ is of type input to define the name of the property

-the variable $type$ defines the type of the property and the list of types in the intellisense

-the variable $NameLower$ Gets the value of the variable $Name$ and change the first character by lowerCase()

image

Therefore ready, now with two clicks I can longer with rare properties these at a stretch Risa

image

Saludos @ La Finca

El Bruno

image image image

Leave a comment

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading