Valentin
Valentin

Reputation: 782

How can you access the class name in a Visual Studio code snippet?

I want to create a code snippet that generates some method that returns an object of the type of the containing class.

More clearly: if I use myCodeSnippet while editing Animal.cs then I want the snippet to generate

public Animal someMethod() { }

Upvotes: 1

Views: 1026

Answers (1)

Valentin
Valentin

Reputation: 782

Add the following literal using the built-in function ClassName():

        <Literal default="true" Editable="false">
            <ID>classname</ID>
            <ToolTip>Class name</ToolTip>
            <Function>ClassName()</Function>
            <Default>ClassNamePlaceholder</Default>
        </Literal>

Then just put $classname$ where you want the class name.

Documentation: Code snippet functions

Upvotes: 4

Related Questions