ClassName() 没有 return 任何,片段工具 visual studio 2013
ClassName() did not return any, snippet tool visual studio 2013
我正在尝试使用 visual studio 中的代码段工具在每个文件中生成版权文本。我创建了一个片段文件如下:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>Copyright (c) 2014, CompanyName</Title>
<Description>License applies to this software </Description>
<Author>CompanyName</Author>
<Shortcut>Copyright</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="false">
<ID>classname</ID>
<ToolTip>Class name</ToolTip>
<Function>ClassName()</Function>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[
/*Copyright file $classname$
*
*Copyright (c) 2015, CompanyName
*
*Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
*2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other
*materials provided with the distribution.
*
*3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific
*prior written permission.
*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
*PURPOSE ARE DISCLAIMED. *IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
*ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED *OF THE POSSIBILITY OF SUCH DAMAGE.
*/]]>
</Code>
</Snippet>
</CodeSnippet>
然而,当我插入此代码时,ClassName() 函数没有 return 任何 Class 名称。
我现在明白你的问题了。如果您在 class 内添加您的代码片段,这将起作用。如果您将其插入顶部的 class 之外,则无法正常工作,因为 class 不是代码段的上下文。
我正在尝试使用 visual studio 中的代码段工具在每个文件中生成版权文本。我创建了一个片段文件如下:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>Copyright (c) 2014, CompanyName</Title>
<Description>License applies to this software </Description>
<Author>CompanyName</Author>
<Shortcut>Copyright</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="false">
<ID>classname</ID>
<ToolTip>Class name</ToolTip>
<Function>ClassName()</Function>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[
/*Copyright file $classname$
*
*Copyright (c) 2015, CompanyName
*
*Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
*2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other
*materials provided with the distribution.
*
*3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific
*prior written permission.
*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
*PURPOSE ARE DISCLAIMED. *IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
*ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED *OF THE POSSIBILITY OF SUCH DAMAGE.
*/]]>
</Code>
</Snippet>
</CodeSnippet>
然而,当我插入此代码时,ClassName() 函数没有 return 任何 Class 名称。
我现在明白你的问题了。如果您在 class 内添加您的代码片段,这将起作用。如果您将其插入顶部的 class 之外,则无法正常工作,因为 class 不是代码段的上下文。