34

有什么方法可以更改代码片段的文字在片段生成的代码中使用时的呈现方式?

具体来说,我想知道我是否可以有一个名为 $PropertyName$ 的文字,然后让代码片段引擎呈现“_$PropertyName$”,其中第一个字符变为小写。

我买不起R#。请帮忙 :)

4

3 回答 3

20

不幸的是,似乎没有办法。如您所见,片段对转换函数的支持非常有限。

您必须坚持使用 VS 标准解决方案,即编写两种文字:一种用于属性名称,另一种用于成员变量名称。

于 2008-10-02T21:40:12.113 回答
5

“修复”可能是在命名或成员变量中使用前缀,即:

string m_$name$;
string $name$
{
 get{return m_$name$;}
 set{m_$name$=value;}
};
于 2013-08-17T13:06:43.537 回答
5

您可以输入一个大写的第一个字母,然后是一个属性名称,然后是一个小写的首字母。试试这个片段:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <Header>
    <Title>Notifiable Property</Title>
    <Author>Nikolay Makhonin</Author>
    <Shortcut>propn</Shortcut>
    <Description>Property With in Built Property Changed method implementation.</Description>
    <SnippetTypes>
      <SnippetType>SurroundsWith</SnippetType>
      <SnippetType>Expansion</SnippetType>
    </SnippetTypes>
  </Header>
  <Snippet>
    <Declarations>
        <Literal>
            <ID>Type</ID>
            <Default>Type</Default>
        </Literal>
        <Literal>
            <ID>P</ID>
            <Default>P</Default>
        </Literal>
        <Literal>
            <ID>roperty</ID>
            <Default>ropertyName</Default>
        </Literal>
        <Literal>
            <ID>p</ID>
            <Default>p</Default>
        </Literal>
        <Literal>
            <ID>Ownerclass</ID>
            <ToolTip>The owning class of this Property.</ToolTip>
            <Function>ClassName()</Function>
            <Default>Ownerclass</Default>
        </Literal>
    </Declarations>
    <Code Language="CSharp">
      <![CDATA[#region $P$$roperty$

        private Field<$Type$> _$p$$roperty$;
        public static readonly string $P$$roperty$PropertyName = GetPropertyName(() => (($Ownerclass$)null).$P$$roperty$);
        public $Type$ $P$$roperty$
        {
            get { return _$p$$roperty$; }
            set { Set(ref _$p$$roperty$, value); }
        }

        #endregion

]]>
    </Code>
  </Snippet>
</CodeSnippet>
于 2017-12-13T09:39:00.223 回答