【问题标题】:ClassName() did not return any, snippet tool visual studio 2013ClassName() 没有返回任何代码片段工具 Visual Studio 2013
【发布时间】:2015-03-28 22:30:03
【问题描述】:

我正在尝试在 Visual Studio 中使用 sn-p 工具在每个文件中生成版权文本。我创建了一个 sn-p 文件如下:

            <?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() 函数没有返回任何类名。

【问题讨论】:

    标签: c# .net visual-studio visual-studio-2013 code-snippets


    【解决方案1】:

    我现在看到了你的问题。如果你在类中添加你的 sn-p 这将起作用。如果您在顶部的类之外插入它,这将无法正常工作,因为该类不是 sn-p 的上下文。

    【讨论】:

    • 然后用这个 ClassNamePlaceholder 代替,但我需要类名
    • 我明白了:D,如果他们有调用文件名的功能会更好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-23
    • 2020-09-07
    • 2016-11-17
    • 2011-07-05
    • 1970-01-01
    • 2011-11-26
    相关资源
    最近更新 更多