As an Episerver developer you will be creating properties on your Page/Block/Media models a lot, and it’s generally a pain to type everything out again and again. Fortunately for us, Visual Studio supports the notion of a Code Snippet that we all know and love such as ctor
, cw
, and even prop
.
While prop
gets us a long way you still want to be setting up the [Display()]
, [CultureSpecific]
, and even [UIHint()]
attributes to improve the editor experience and follow general best practice. In that vein, I’ve created a set of Episerver-specific code snippets to make life easier for someone as type-lazy as I am and I thought I should share it as it truly is a productivity improvement.
This is the full list:
// Snippet shortcut followed by result
//epstr
[CultureSpecific]
[Display(
Name = "Heading",
Description = "",
GroupName = SystemTabNames.Content,
Order = 10)]
[UIHint(UIHint.LongString)]
public virtual string Heading { get; set; }
//eprte
[CultureSpecific]
[Display(
Name = "Body",
Description = "",
GroupName = SystemTabNames.Content,
Order = 10)]
public virtual XhtmlString Body { get; set; }
//epint
[Display(
Name = "Number",
Description = "",
GroupName = SystemTabNames.Content,
Order = 10)]
public virtual int Number { get; set; }
//epbool
[CultureSpecific]
[Display(
Name = "DisplaySection",
Description = "",
GroupName = SystemTabNames.Content,
Order = 10)]
public virtual bool DisplaySection { get; set; }
//epcntr
[CultureSpecific]
[Display(
Name = "SelectedContent",
Description = "",
GroupName = SystemTabNames.Content,
Order = 10)]
[AllowedTypes(new[] { typeof(Block) })]
public virtual ContentReference SelectedContent { get; set; }
//epcntri
[CultureSpecific]
[Display(
Name = "SelectedContent",
Description = "",
GroupName = SystemTabNames.Content,
Order = 10)]
[UIHint(UIHint.Image)]
public virtual ContentReference SelectedContentImage { get; set; }
//epcnta
[CultureSpecific]
[Display(
Name = "BlockArea",
Description = "",
GroupName = SystemTabNames.Content,
Order = 10)]
[AllowedTypes(new[] { typeof(Block) })]
public virtual ContentArea BlockArea { get; set; }
For simplicity’s sake, each file name corresponds to the shortcut for using that snippet, and all “Name” fields contain a single word for double-click-to-select convenience.
First, you need to download and extract the snippets from here 👉 Epi_VS_Snippets.zip 👈
Then open up Visual Studio and go to Tools > Code Snippets Manager (or hit Ctrl+K, Ctrl + B)
Select the Import.. button
Navigate to where you extracted the zip file from above, select all snippets and click open
Make sure “My Code Snippets” is ticked as the location, and click Finish
Finally, close out of the Code Snippets Manager by clicking OK.
Congratulations that’s all there is to it, now you can use these snippets and save yourself some effort by hitting tab twice.
Feel free to update these snippets as you see fit and then reimport them into VS, or if these inspire you to create more cool ones why not come share them with us on github.
Thanks for stopping by.