开发者

VS Code snippet and SimpleTypeName - different results depending upon order in XML?

I'm writing a little snippet to generate C# properties (as have many before me no doubt). I would like to add various attributes in the generated code, and would like to use the "SimpleTypeName" function. However, it seems that it doesn't always work, depending upon the order of the usage in the source XML file.

Specifically, given snippet XML like this...

<Snippet>
  <Declarations>
    <Literal Editable="false">
      <ID>DesignerSerializationVisibility</ID>
      <Function>SimpleTypeName(global::System.ComponentModel.DesignerSerializationVisibility)</Function>
    </Literal>
    <Literal Editable="false">
      <ID>DebuggerStepThrough</ID>
      <Function>SimpleTypeName(global::System.Diagnostics.DebuggerStepThrough)</Function>
    </Literal>
  </Declarations>

  <Code Language="CSharp">
    <![CDATA[

      [$DebuggerStepThrough$(),
       $DesignerSerializationVisibility$($DesignerSerializationVisibility$.Hidden)]
      public object x {get;set;}    

      [$DesignerSerializationVisibility$($DesignerSerializationVisibility$.Hidden),
       $DebuggerStepThrough$()]
      public object z {get;set;}    

    ]]>
  </Code>
</Snippet>

...and the appropriate "using" statements in my source file, I get code like this...

  [DebuggerStepThrough(),
   DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  public object x { get; set; }

  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
   开发者_如何转开发DebuggerStepThrough()]
  public object z { get; set; }

All fine and dandy. If, however, I change my snippet XML to be this (note just the order of the functions has changed)...

<Snippet>
  <Declarations>
    <Literal Editable="false">
      <ID>DesignerSerializationVisibility</ID>
      <Function>SimpleTypeName(global::System.ComponentModel.DesignerSerializationVisibility)</Function>
    </Literal>
    <Literal Editable="false">
      <ID>DebuggerStepThrough</ID>
      <Function>SimpleTypeName(global::System.Diagnostics.DebuggerStepThrough)</Function>
    </Literal>
  </Declarations>

  <Code Language="CSharp">
    <![CDATA[

      [$DesignerSerializationVisibility$($DesignerSerializationVisibility$.Hidden),
       $DebuggerStepThrough$()]
      public object z {get;set;}    

      [$DebuggerStepThrough$(),
       $DesignerSerializationVisibility$($DesignerSerializationVisibility$.Hidden)]
      public object x {get;set;}    

    ]]>
  </Code>
</Snippet>

...I get this as the inserted C# code:

  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
   global::System.Diagnostics.DebuggerStepThrough()]
  public object z { get; set; }

  [global::System.Diagnostics.DebuggerStepThrough(),
   DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  public object x { get; set; } 

Why does my call to SimpleTypeName(DebuggerStepThrough) seem not to work when the XML is written using the order in the second example ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜