Autogenerating Snippet  
Author Message
tkrasinger





PostPosted: Visual C# IDE, Autogenerating Snippet Top

Is there a way, to autogenerate a snippet, without any user-action necessary

I want to create a class-name-depending snippet creating code like that:


public class Person
{
public static void MethodWrapper() {
DAOPerson.MethodWrapper();
}

[TableName("Person")]
public static DAOPerson ProcedureCall() {
return DAOPerson.DoSomething();
}
}


so i will have to create following snippet, when i want to insert to method-code:


public static void MethodWrapper() {
DAO$ClassName$.MethodWrapper();
}

[TableName("$ClassName$")]
public static DAO$ClassName$ ProcedureCall() {
return DAO$ClassName$.DoSomething();
}

What i want is: When I'm in the class Person, "calling" the snippet, I now have to type "Person" for the wanted result. Is there a possibility to create the snippet "autogenerating" Means: The snippet evaluates the var $ClassName$ from the current class I am in, and autogenerates to code, so that i don't have to type something anymore



Visual C#16  
 
 
Karen Liu MSFT





PostPosted: Visual C# IDE, Autogenerating Snippet Top

Yep -- the way to do this is to use the ClassName() function as the literal. This returns the name of the class that contains the inserted snippet.

For your example, this would be the <snippet></snippet> portion:

<Snippet>
<Declarations>
<Literal>
<ID>ClassName</ID>
<ToolTip>Containing Class</ToolTip>
<Function>ClassName()</Function>
</Literal>

</Declarations>

<Code Language="csharp"><![CDATA[

public static void MethodWrapper() {
DAO$ClassName$.MethodWrapper();
}

[TableName("$ClassName$")]
public static DAO$ClassName$ ProcedureCall() {
return DAO$ClassName$.DoSomething();
}

]]>

</Code>
</Snippet>

HTH,
Karen



 
 
tkrasinger





PostPosted: Visual C# IDE, Autogenerating Snippet Top

Thanks, works perfect !