BaseColumns 不包含采用 0 个参数的构造函数

BaseColumns does not contain a constructor that takes 0 arguments

我正在将 Android Studio 项目移植到 Visual Studio / Xamarin. 我有这个 Java 代码:

public class EmployeeDataContract {
    public EmployeeDataContract() { }

    public static abstract class EmployeeDataEntry implements BaseColumns {
        public static final String TABLE_NAME = "tblEmployeeData"; // Local SQLLite table
        public static final String COLUMN_NAME_LOCAL_ID = "_id";

翻译成 C#:

public class EmployeeDataContract {
    public EmployeeDataContract() {}

    public abstract class EmployeeDataEntry : BaseColumns  { // had to remove "static"
        public const string TABLE_NAME = "tblEmployeeData"; // Local SQLLite table
        public const string COLUMN_NAME_LOG_ID = "_id";

Visual Studio给出编译错误:
BaseColumns 不包含采用 0 个参数的构造函数

然后我去查看BaseColumns,它不包含构造函数,也没有继承class(可能有构造函数),因此它继承自Object,它应该有一个带有 0 个参数的构造函数。

有什么问题?

此处有关于此行为的错误报告:https://bugzilla.xamarin.com/show_bug.cgi?id=36791

基本上在 Java 中,此接口仅包含两个常量,定义 id 和 count 列的名称。在 C# 中,接口不能包含常量,因此像您看到的那样,此类常量被移动到抽象 class 中。它不能被继承(在其他程序集中),因为它只有构造函数是内部的,子 class 应该调用父的构造函数。因为此接口包含 个常量,所以 xamarin 不会为其生成(空)接口。

如果您手动移植代码(不绑定到 Java 库)- 也许 您可以忽略从这个 class 继承,因为它确实无论如何不提供任何有用的东西。当然,其他一些代码可能只接受此 class 的实例,但这不太可能。