我正在使用SyntaxGenerator即时创建一些代码。我需要向属性添加属性。这是我所拥有的:
var g = // some SyntaxGenerator
var attributes = new List<SyntaxNode>
{
g.Attribute("System.Xml.Serialization.XmlAttributeAttribute")
};
var property = g.PropertyDeclaration(
name, // The property name
type, // A SyntaxNode resembling the type
accessibility: Accessibility.Public,
getAccessorStatements: getModifiers,
setAccessorStatements: setModifiers);
g.AddAttributes(property, attributes); // Does nothing
我希望属性显示如下:
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Id
{
get
{
return this.id;
}
set
{
this.id = value;
}
}
如何添加属性?
原来我忘了这样做(由于AddAttributes()创建了SyntaxNode的新实例,所以很简单:
property = g.AddAttributes(property, attributes);