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

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

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

有帮助吗?

解决方案

不幸的是似乎没有办法。片段为转换功能提供非常有限的支持可以看到。

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

其他提示

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

string m_$name$;
string $name$
{
 get{return m_$name$;}
 set{m_$name$=value;}
};

您可以输入较高的第一个字母,然后输入属性名称,然后输入较低的第一个字母。试试这个片段:

<?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<*>gt; _$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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top