编译器错误 CS0570

语言不支持属性、索引器或事件“name”;尝试直接调用访问器方法“name!”

使用由另一个编译器生成的导入的元数据时,会发生此错误。 代码尝试使用编译器无法处理的类成员。

注释

此警告仅在显式 生成重新生成 作业期间报告。 在 IDE 中键入期间不会将它显示为 IntelliSense 诊断的一部分。 这意味着,如果通过使用该字段或删除字段来修复警告,则警告可能会保留在错误列表中,直到您再次编译或重新编译项目。

示例 1

以下C++程序使用属性 RequiredAttributeAttribute,该属性可能不受其他语言使用。

// CPP0570.cpp  
// compile with: /clr /LD  
  
using namespace System;  
using namespace System::Runtime::CompilerServices;  
  
namespace CS0570_Server {  
   [RequiredAttributeAttribute(Int32::typeid)]
   public ref struct Scenario1 {  
      int intVar;  
   };  
  
   public ref struct CS0570Class {  
      Scenario1 ^ sc1_field;  
  
      property virtual Scenario1 ^ sc1_prop {  
         Scenario1 ^ get() { return sc1_field; }  
      }  
  
      Scenario1 ^ sc1_method() { return sc1_field; }  
   };  
};  

示例 2

下面的示例会产生错误代码 CS0570。

// CS0570.cs  
// compile with: /reference:CPP0570.dll  
using System;  
using CS0570_Server;  
  
public class C {  
   public static int Main() {  
      CS0570Class r = new CS0570Class();  
      r.sc1_field = null;   // CS0570  
      object o = r.sc1_prop;   // CS0570  
      r.sc1_method();   // CS0570  
   }  
}