使用CodeDOM生成C#代码时,将CodeCommentStatement添加到CodeMemberProperty
当使用CodeDOM生成C#代码时,有人知道如何将CodeCommentStatement添加到CodeMemberProperty吗 我试过:使用CodeDOM生成C#代码时,将CodeCommentStatement添加到CodeMemberProperty,c#,codedom,C#,Codedom,当使用CodeDOM生成C#代码时,有人知道如何将CodeCommentStatement添加到CodeMemberProperty吗 我试过: var docStart = new CodeCommentStatement("<summary>", true); var docContent = new CodeCommentStatement("The description of property", true); var docEnd = new CodeCommentSta
var docStart = new CodeCommentStatement("<summary>", true);
var docContent = new CodeCommentStatement("The description of property", true);
var docEnd = new CodeCommentStatement("</summary>", true);
var property = new CodeMemberProperty {
Name = name,
HasGet = true,
Attributes = MemberAttributes.Public | MemberAttributes.Static,
Type = new CodeTypeReference(typeof(byte[]))
};
var documentation = new CodeCommentStatementCollection { docStart, docContent, docEnd}
property.Comments = new CodeCommentStatementCollection(documentation);
var docStart=newcodecommentstatement(“”,true);
var docContent=newcodecommentstatement(“属性描述”,true);
var docEnd=newcodecommentstatement(“,true);
var属性=新的CodeMemberProperty{
Name=Name,
HasGet=true,
Attributes=MemberAttributes.Public | MemberAttributes.Static,
Type=新的代码类型引用(typeof(byte[]))
};
var documentation=new CodeCommentStatementCollection{docStart,docContent,docEnd}
property.Comments=新的CodeCommentStatementCollection(文档);
但是注释属性没有设置器
有解决办法吗 我建议将这些项添加到现有的
CodeCommentStatementCollection
中,而不是创建一个新项:
CodeCommentStatement[] documentation = { docStart, docContent, docEnd}
property.Comments.AddRange(documentation);
集合提供了用于添加以下内容的常用方法:对于数组,对于CodeCommentStatementCollection
正如@svick在注释中指出的,您还可以在实例化对象时指定值,例如
var property = new CodeMemberProperty {
// Other initialization values
Comments = { docStart, docContent, docEnd } }
如果您想知道为什么以及如何在只读属性上工作,请查看此项及其答案。我建议将这些项添加到现有的
CodeCommentStatementCollection
中,而不是创建一个新项:
CodeCommentStatement[] documentation = { docStart, docContent, docEnd}
property.Comments.AddRange(documentation);
集合提供了用于添加以下内容的常用方法:对于数组,对于CodeCommentStatementCollection
正如@svick在注释中指出的,您还可以在实例化对象时指定值,例如
var property = new CodeMemberProperty {
// Other initialization values
Comments = { docStart, docContent, docEnd } }
如果您想知道为什么以及如何在只读属性上工作,请查看此项及其答案。我建议将这些项添加到现有的
CodeCommentStatementCollection
中,而不是创建一个新项:
CodeCommentStatement[] documentation = { docStart, docContent, docEnd}
property.Comments.AddRange(documentation);
集合提供了用于添加以下内容的常用方法:对于数组,对于CodeCommentStatementCollection
正如@svick在注释中指出的,您还可以在实例化对象时指定值,例如
var property = new CodeMemberProperty {
// Other initialization values
Comments = { docStart, docContent, docEnd } }
如果您想知道为什么以及如何在只读属性上工作,请查看此项及其答案。我建议将这些项添加到现有的
CodeCommentStatementCollection
中,而不是创建一个新项:
CodeCommentStatement[] documentation = { docStart, docContent, docEnd}
property.Comments.AddRange(documentation);
集合提供了用于添加以下内容的常用方法:对于数组,对于CodeCommentStatementCollection
正如@svick在注释中指出的,您还可以在实例化对象时指定值,例如
var property = new CodeMemberProperty {
// Other initialization values
Comments = { docStart, docContent, docEnd } }
如果您想知道为什么以及如何在只读属性上工作,请查看此内容及其答案。您也可以在对象创建表达式中执行此操作:
newcodemberproperty{Comments={docStart,…}}
@svick:感谢您的添加。我花了一些时间来弄清楚这在只读属性上是如何工作的——今天我确实学到了一些新东西。我已经更新了答案。谢谢@Markus和@svick!您也可以在对象创建表达式中执行此操作:newcodemberproperty{Comments={docStart,…}
@svick:谢谢您的添加。我花了一些时间来弄清楚这在只读属性上是如何工作的——今天我确实学到了一些新东西。我已经更新了答案。谢谢@Markus和@svick!您也可以在对象创建表达式中执行此操作:newcodemberproperty{Comments={docStart,…}
@svick:谢谢您的添加。我花了一些时间来弄清楚这在只读属性上是如何工作的——今天我确实学到了一些新东西。我已经更新了答案。谢谢@Markus和@svick!您也可以在对象创建表达式中执行此操作:newcodemberproperty{Comments={docStart,…}
@svick:谢谢您的添加。我花了一些时间来弄清楚这在只读属性上是如何工作的——今天我确实学到了一些新东西。我已经更新了答案。谢谢@Markus和@svick!