Click here to Skip to main content
13,048,846 members (69,041 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.7K views
1 bookmarked
Posted 12 Jan 2011

Shortcut to generate different property snippets in Visual Studio

, 13 Jan 2011
Rate this:
Please Sign up or sign in to vote.
I ended up adding one for a Lazy Property: propLazy ...
I ended up adding one for a Lazy Property:

<?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:

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)

Share

About the Author

cechode
United States United States
No Biography provided

You may also be interested in...

Pro

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
memberMahmudul 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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 14 Jan 2011
Article Copyright 2011 by cechode
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid