Suggestion for small change to snippets

Suggestion for small change to snippets

Old forum URL: forums.lhotka.net/forums/t/4609.aspx


Cine posted on Wednesday, April 02, 2008

VS can determine the classname of the current function, so no need to type that manually.
The Property field can also be made readonly since (hopefully) you never write it to again. It also makes for a micro-optimization in the JIT code (not quite sure why though, seems to be related to a better type interference).
Also remove generic type on RegisterProperty, it is inferred by the compiler.

Index: DefineACslaProperty.snippet
===================================================================
--- DefineACslaProperty.snippet    (revision 2235)
+++ DefineACslaProperty.snippet    (working copy)
@@ -9,11 +9,11 @@
     </Header>
     <Snippet>
       <Declarations>
-        <Literal>
+        <Literal Editable="false">
           <ID>ClassName</ID>
-          <Type>String</Type>
-          <ToolTip>Replace with class name.</ToolTip>
-          <Default>BusinessClass</Default>
+          <Function>ClassName()</Function>
+          <ToolTip>Class name.</ToolTip>
+          <Default>BusinessClassNamePlaceHolder</Default>
         </Literal>
         <Literal>
           <ID>PropertyName</ID>
@@ -25,7 +25,7 @@
           <ID>FriendlyName</ID>
           <Type>String</Type>
           <ToolTip>Replace with friendly property name.</ToolTip>
-          <Default>Name</Default>
+          <Default>FriendlyName</Default>
         </Literal>
         <Literal>
           <ID>PropertyType</ID>
@@ -34,7 +34,7 @@
         </Literal>
       </Declarations>
       <Code Language="CSharp" Kind="method decl">
-  <![CDATA[private static PropertyInfo<$PropertyType$> $PropertyName$Property = RegisterProperty<$PropertyType$>(typeof($ClassName$), new PropertyInfo<$PropertyType$>("$PropertyName$", "$FriendlyName$"));
+  <![CDATA[private static readonly PropertyInfo<$PropertyType$> $PropertyName$Property = RegisterProperty(typeof($ClassName$), new PropertyInfo<$PropertyType$>("$PropertyName$", "$FriendlyName$"));
 public $PropertyType$ $PropertyName$
 {
   get { return GetProperty<$PropertyType$>($PropertyName$Property); }
Index: DefineACslaReadonlyProperty.snippet
===================================================================
--- DefineACslaReadonlyProperty.snippet    (revision 2235)
+++ DefineACslaReadonlyProperty.snippet    (working copy)
@@ -9,11 +9,11 @@
     </Header>
     <Snippet>
       <Declarations>
-        <Literal>
+        <Literal Editable="false">
           <ID>ClassName</ID>
-          <Type>String</Type>
-          <ToolTip>Replace with class name.</ToolTip>
-          <Default>BusinessClass</Default>
+          <Function>ClassName()</Function>
+          <ToolTip>Class name.</ToolTip>
+          <Default>BusinessClassNamePlaceHolder</Default>
         </Literal>
         <Literal>
           <ID>PropertyName</ID>
@@ -25,7 +25,7 @@
           <ID>FriendlyName</ID>
           <Type>String</Type>
           <ToolTip>Replace with friendly property name.</ToolTip>
-          <Default>Name</Default>
+          <Default>FriendlyName</Default>
         </Literal>
         <Literal>
           <ID>PropertyType</ID>
@@ -34,7 +34,7 @@
         </Literal>
       </Declarations>
       <Code Language="CSharp" Kind="method decl">
-        <![CDATA[private static PropertyInfo<$PropertyType$> $PropertyName$Property = RegisterProperty<$PropertyType$>(typeof($ClassName$), new PropertyInfo<$PropertyType$>("$PropertyName$", "$FriendlyName$"));
+        <![CDATA[private static readonly PropertyInfo<$PropertyType$> $PropertyName$Property = RegisterProperty<$PropertyType$>(typeof($ClassName$), new PropertyInfo<$PropertyType$>("$PropertyName$", "$FriendlyName$"));
 public $PropertyType$ $PropertyName$
 {
   get { return GetProperty<$PropertyType$>($PropertyName$Property); }
Index: DefineACslaSmartDateProperty.snippet
===================================================================
--- DefineACslaSmartDateProperty.snippet    (revision 2235)
+++ DefineACslaSmartDateProperty.snippet    (working copy)
@@ -9,17 +9,17 @@
     </Header>
     <Snippet>
       <Declarations>
-        <Literal>
+        <Literal Editable="false">
           <ID>ClassName</ID>
-          <Type>String</Type>
-          <ToolTip>Replace with class name.</ToolTip>
-          <Default>BusinessClass</Default>
+          <Function>ClassName()</Function>
+          <ToolTip>Class name.</ToolTip>
+          <Default>BusinessClassNamePlaceHolder</Default>
         </Literal>
         <Literal>
           <ID>FriendlyName</ID>
           <Type>String</Type>
           <ToolTip>Replace with friendly property name.</ToolTip>
-          <Default>Name</Default>
+          <Default>FriendlyName</Default>
         </Literal>
         <Literal>
           <ID>PropertyName</ID>
@@ -29,7 +29,7 @@
         </Literal>
       </Declarations>
       <Code Language="CSharp" Kind="method decl">
-        <![CDATA[private static PropertyInfo<SmartDate> $PropertyName$Property = RegisterProperty<SmartDate>(typeof($ClassName$), new PropertyInfo<SmartDate>("$PropertyName$", "$FriendlyName$", new SmartDate()));
+        <![CDATA[private static readonly PropertyInfo<SmartDate> $PropertyName$Property = RegisterProperty(typeof($ClassName$), new PropertyInfo<SmartDate>("$PropertyName$", "$FriendlyName$", new SmartDate()));
 public string $PropertyName$
 {
   get { return GetProperty<SmartDate, string>($PropertyName$Property); }
Index: AddFactoryMethods.snippet
===================================================================
--- AddFactoryMethods.snippet    (revision 2235)
+++ AddFactoryMethods.snippet    (working copy)
@@ -11,8 +11,8 @@
       <Declarations>
         <Literal>
           <ID>ClassName</ID>
-          <Type>String</Type>
-          <ToolTip>Replace with class name.</ToolTip>
+          <Function>ClassName()</Function>
+          <ToolTip>Class name.</ToolTip>
           <Default>BusinessClass</Default>
         </Literal>
         <Literal>


Copyright (c) Marimer LLC