我正在编写一个小片段来生成C#属性(毫无疑问,我之前有很多)。我想在生成的代码中添加各种属性,并希望使用“SimpleTypeName”函数。但是,它似乎并不总是有效,具体取决于源XML文件中的使用顺序。
具体来说,给出了像这样的片段XML ......
<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>
...和我的源文件中的相应“使用”语句,我得到这样的代码...
[DebuggerStepThrough(),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public object x { get; set; }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
DebuggerStepThrough()]
public object z { get; set; }
一切都很好,花花公子。但是,如果我将我的代码段XML更改为(请注意函数的顺序已更改) ...
<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>
...我将其作为插入的C#代码:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
global::System.Diagnostics.DebuggerStepThrough()]
public object z { get; set; }
[global::System.Diagnostics.DebuggerStepThrough(),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public object x { get; set; }
为什么在使用第二个示例中的顺序编写XML时,我对SimpleTypeName(DebuggerStepThrough)的调用似乎不起作用?