Language-Ext Unions - 目标运行时不支持默认接口实现
Language-Ext Unions - Target runtime doesn't support default interface implementation
我正在尝试在 Language-Ext 中使用 Union 类型,但出现错误:方法名称的“目标运行时不支持默认接口实现”和“类型或名称空间名称 'InconsistentFirstName'找不到
我的代码如下所示:
[Union]
public interface Inconsistency
{
public Inconsistency InconsistentFirstName(string localValue, string contactCentreValue);
public Inconsistency InconsistentSurname(string localValue, string contactCentreValue);
public string GetFieldName(Inconsistency inconsistency)
=> inconsistency switch
{
InconsistentFirstName n => "Name",
InconsistenctSurname s => "Surname",
_ => ""
};
}
GetFieldName
需要添加到单独的 class 文件中。有一个部分 class 是自动生成的代码,称为 InconsistencyCon
,所以我试图实现的可以使用以下代码完成:
[Union]
public abstract partial class Inconsistency
{
public abstract Inconsistency InconsistentFirstName(string localValue, string remoteValue);
public abstract Inconsistency InconsistentSurname(string localValue, string remoteValue);
}
public static partial class InconsistencyCon
{
public static string FieldName(this Inconsistency inconsistency) =>
inconsistency switch
{
InconsistentFirstName n => "Name",
InconsistentSurname s => "Surname",
_ => ""
};
public static string Test(Inconsistency inconsistency)
{
if (inconsistency is InconsistentFirstName n)
{
var a = n.LocalValue;
var b = n.FieldName;
// etc
}
}
}
我正在尝试在 Language-Ext 中使用 Union 类型,但出现错误:方法名称的“目标运行时不支持默认接口实现”和“类型或名称空间名称 'InconsistentFirstName'找不到
我的代码如下所示:
[Union]
public interface Inconsistency
{
public Inconsistency InconsistentFirstName(string localValue, string contactCentreValue);
public Inconsistency InconsistentSurname(string localValue, string contactCentreValue);
public string GetFieldName(Inconsistency inconsistency)
=> inconsistency switch
{
InconsistentFirstName n => "Name",
InconsistenctSurname s => "Surname",
_ => ""
};
}
GetFieldName
需要添加到单独的 class 文件中。有一个部分 class 是自动生成的代码,称为 InconsistencyCon
,所以我试图实现的可以使用以下代码完成:
[Union]
public abstract partial class Inconsistency
{
public abstract Inconsistency InconsistentFirstName(string localValue, string remoteValue);
public abstract Inconsistency InconsistentSurname(string localValue, string remoteValue);
}
public static partial class InconsistencyCon
{
public static string FieldName(this Inconsistency inconsistency) =>
inconsistency switch
{
InconsistentFirstName n => "Name",
InconsistentSurname s => "Surname",
_ => ""
};
public static string Test(Inconsistency inconsistency)
{
if (inconsistency is InconsistentFirstName n)
{
var a = n.LocalValue;
var b = n.FieldName;
// etc
}
}
}