Click here to Skip to main content
15,881,089 members
Articles / Desktop Programming / WPF
Alternative
Tip/Trick

Shortcut to generate different property snippets in Visual Studio

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
13 Jan 2011CPOL 8.8K   1   1
I ended up adding one for a Lazy Property: propLazy ...
I ended up adding one for a Lazy Property:

XML
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>propLazy</Title>
            <Shortcut>proplazy</Shortcut>
            <Description>Code snippet for property and lazy backing field</Description>
            <Author>ME</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>type</ID>
                    <ToolTip>Property type</ToolTip>
                    <Default>string</Default>
                </Literal>
                <Literal>
                    <ID>property</ID>
                    <ToolTip>Property name</ToolTip>
                    <Default>MyProperty</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp">
                <![CDATA[private System.Lazy<$type$> _$property$ = new System.Lazy<$type$>();
public $type$ $property${ get{ return _$property$.Value; } set{_$property$ = new Lazy<$type$>(() => value);} }
    $end$]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>


which produces:

C#
private System.Lazy<string> _MyProperty = new System.Lazy<string>();
public string MyProperty { get { return _MyProperty.Value; } set { _MyProperty = new Lazy<string>(() => value); } }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralReason for my vote of 5 Its a good one! May be in VS 2011 or... Pin
Mahmudul Haque Azad12-Jan-11 15:21
Mahmudul Haque Azad12-Jan-11 15:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.