ClassName()没有返回任何内容,片段工具Visual Studio 2013。

4

我正在尝试使用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()函数没有返回任何类名。
1个回答

4

我现在明白你的问题了。如果你把代码片段放在类里面,它就会起作用。如果你把代码片段插入到类之外的顶部,它就不能起作用,因为类不是代码片段的上下文。


然后它被替换为这个ClassNamePlaceholder,但我需要类名。 - Jovirus
3
我明白了:D,如果他们有一个调用文件名的功能会更好。 - Jovirus

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接