2010-02-11 46 views
4

我已經定居在創建特性(與支持字段)的以下樣式:如何在VS2008片段中強制使用UpperCase?

private _firstName; 
public string FirstName 
{ 
    get { return _firstName; } 
    set { _firstName = value; } 
} 

鑑於屬性的名稱相似,支持字段的名字,我已經改善內置在prop片斷以下幾點:

<?xml version="1.0"?> 
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> 
    <CodeSnippet Format="1.0.0"> 
    <Header> 
     <Title>prop</Title> 
     <Author>Frank Rizzo</Author> 
     <Description>Code snippet for property and backing field - changed one (not the original).</Description> 
     <Shortcut>prop</Shortcut> 
     <SnippetTypes> 
     <SnippetType>Expansion</SnippetType> 
     </SnippetTypes> 
    </Header> 
    <Snippet> 
     <Declarations> 
     <Literal> 
      <ID>type</ID> 
      <ToolTip>Property type</ToolTip> 
      <Default>int</Default> 
     </Literal> 
     <Literal> 
      <ID>property</ID> 
      <ToolTip>Property name</ToolTip> 
      <Default>MyProperty</Default> 
     </Literal> 
     <Literal> 
      <ID>field</ID> 
      <ToolTip>The variable backing this property</ToolTip> 
      <Default>myVar</Default> 
     </Literal> 
     </Declarations> 
     <Code Language="CSharp"><![CDATA[private $type$ _$field$; 

    public $type$ $field$ 
    { 
     get { return _$field$;} 
     set { _$field$ = value;} 
    } 
    $end$ 
      ]]></Code> 
    </Snippet> 
    </CodeSnippet> 
</CodeSnippets> 

此作品在一定程度上,但支持字段的外殼和屬性名稱是始終不變的,在這裏爲我的約定,支持字段是駱駝,套管,作爲屬性名稱是pascal-cased。

所以我的問題是這樣的:snippet語法是否有方法來改變屬性的第一個字母,以便該片段可能符合我的約定?

回答

6

不幸的是,這是不可能的(但)。

希望在未來的Visual Studio版本中有可能。

+1

SLaks是正確的,片段在許多方面還沒有得到很好的支持。 (在IDE中沒有編輯器,在VS 2010中**仍然**是這方面的證據) – 2010-02-11 23:52:56

+2

剛剛發現此答案*嘆息* ... – notJim 2010-06-26 21:54:15

-2
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> 
    <Header> 
    <Title>Code File Header</Title> 
    <Author>Муся</Author> 
    <Shortcut>codehead</Shortcut> 
    <Description>Гавнокодец</Description> 
    <SnippetTypes> 
     <SnippetType>Expansion</SnippetType> 
    </SnippetTypes> 
    </Header> 
    <Snippet> 
    <Declarations> 
     <Literal> 
     <ID>Name</ID> 
     <Default>Header</Default> 
     </Literal> 
     <Literal> 
     <ID>LowerName</ID> 
     <Default>header</Default> 
     </Literal> 
     <Literal> 
     <ID>Type</ID> 
     <Default>object</Default> 
     </Literal> 
    </Declarations> 
    <Code Language="CSharp"> 
     <![CDATA[ 
     public $Type$ $Name$ 
     { 
      get { return $LowerName$; } 
      set 
      { 
       $LowerName$ = value; 
       OnPropertyChanged("$Name$"); 
      } 
     } 
     $Type$ $LowerName$; 
     ]]> 
    </Code> 
    </Snippet> 
</CodeSnippet> 
+1

請指定問題提示器在您的代碼塊之外需要做什麼。 – JoshDM 2012-12-12 18:49:34

+1

您的代碼看起來並不像是實際進行任何大小寫轉換。 – Sam 2013-11-22 22:12:08