Configuration Property CodeRush Template

Posted on 31st January 2008 in CodeRush

I have been busy this week creating our company’s subscription service, more on that later.

As part of this I am integrating with PayPal to enable recurring payments.  The PayPal service has a number of configuration options to work with, merchant IDs, IPN handler locations, PDT handler locations, API locations etc.

I started writing my own configuration section handler for PayPal and became bored writing the properties, so I came up with these templates for CodeRush.  We all need something to relieve the boredom of repetitive tasks: –

Template Name : scp

[ConfigurationProperty("«Caret»«FieldStart(Setting Name)»«Link(settingName)»«FieldEnd»", «Field(Optional, OptionalSettings)»)]
public object «Field(Setting, Setting Name)»
{
    get {return base["«Link(settingName)»"];}
    set {base["«Link(settingName)»"] = value;}
}«Target»

Template Name : scp?Type?

[ConfigurationProperty("«Caret»«FieldStart(Setting Name)»«Link(settingName)»«FieldEnd»«BlockAnchor»", «Field(Optional, OptionalSettings)»)]
public «TypeLink(“«?Get(Type)»”)» «Field(Setting, Setting Name)»
{
    get {return («TypeLink(“«?Get(Type)»”)»)base["«Link(settingName)»"];}
    set {base["«Link(settingName)»"] = value;}
}«Target»

Typing scps<space> will expand with the following results: –

[ConfigurationProperty("settingName", Optional)]
public string Setting
{
    get {return (string)base["settingName"];}
    set {base["settingName"] = value;}
}

Typing scp<space> will expand with the following results: -

[ConfigurationProperty("settingName", Optional)]
public object Setting
{
    get {return base["settingName"];}
    set {base["settingName"] = value;}
}

In both cases the “settingName” string will be linked, changing one will change all.  Also the first “settingName” will be highlighted.  Once you are done changing this string hitting <enter> will take you to and highlight Optional, hitting <enter> again once you are done with the optional values will place your cursor after the }.  In the case of scps both of the string types will be linked, changing one will change both.

If anyone is interested in understanding these templates in more detail please let me know.

comments: Comments Off