Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Shortcut to generate different property snippets in Visual Studio

, 13 Jan 2011 CPOL
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

Comments and Discussions

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

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 14 Jan 2011
Article Copyright 2011 by cechode
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid