C# 不使用CodeDom生成抽象类
我有这样一个类定义:C# 不使用CodeDom生成抽象类,c#,.net,dynamic,metaprogramming,codedom,C#,.net,Dynamic,Metaprogramming,Codedom,我有这样一个类定义: CodeTypeDeclaration helloWorldClass = new CodeTypeDeclaration("HelloWorld") { Attributes = MemberAttributes.Abstract | MemberAttributes.Public }; 为什么这个声明会生成一个非抽象类 您需要使用而不是成员属性: CodeTypeDeclaration helloWorldClass = new CodeTypeDeclar
CodeTypeDeclaration helloWorldClass = new CodeTypeDeclaration("HelloWorld") {
Attributes = MemberAttributes.Abstract | MemberAttributes.Public
};
为什么这个声明会生成一个非抽象类
您需要使用而不是成员属性
:
CodeTypeDeclaration helloWorldClass = new CodeTypeDeclaration("HelloWorld")
{
TypeAttributes = TypeAttributes.Abstract | TypeAttributes.Public
};
为什么他们要添加属性属性,如果它在
定义类型
在以下文件中明确规定:
一些标志(如抽象)与标志的含义重叠
在继承的CodeTypeDeclaration的Attributes属性中
来自CodeTypeMember属性属性是
从CodeTypeMember继承的CodeTypeDeclaration类,以便
类可以嵌套。TypeAttributes属性中的标志应为
不能使用属性属性中的标志。
为了使用这样一个继承层次结构,他们对复制做了一些轻微的混淆。这就是为什么好的文档很重要。可能是
TypeAttributes=TypeAttributes.Abstract
?就是这样!!如果定义类型时属性不起作用,为什么要添加属性呢?@MatiCicero因为它们是MemberAttributes
,它们适用于成员,而不是类型。我认为属性是字段、属性、方法等的。@MatiCicero因为类型可以是类的成员。@MatiCicero欢迎您。很高兴这有意义。
CodeTypeDeclaration helloWorldClass = new CodeTypeDeclaration("HelloWorld")
{
TypeAttributes = TypeAttributes.Abstract | TypeAttributes.Public
};