Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 不使用CodeDom生成抽象类_C#_.net_Dynamic_Metaprogramming_Codedom - Fatal编程技术网

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
};