gpt4 book ai didi

c# - WCF DataContract 与 DataContract 接口(interface)

转载 作者:可可西里 更新时间:2023-11-01 09:10:40 28 4
gpt4 key购买 nike

WCF 新手。

DataContact 类可以继承自 Interface 吗?

例如:

[DataContract(Namespace = ...........)]
public class VesselSequence : IVesselSequence
{

[DataMember]
public int AllocationId { get; set; }

[DataMember]
public string ScenarioName { get; set; }
}

interface VesselSequence : IVesselSequence
{
public int AllocationId { get; set; }
public string ScenarioName { get; set; }
}

最佳答案

你可以这样做:

[DataContract(Namespace = ...........)]
public class VesselSequence : IVesselSequence
{
[DataMember]
public int AllocationId { get; set; }
[DataMember]
public string ScenarioName { get; set; }
}

interface IVesselSequence
{
int AllocationId { get; set; }
string ScenarioName { get; set; }
}

遗憾的是,你不能这样做:

public class VesselSequence : IVesselSequence
{
public int AllocationId { get; set; }
public string ScenarioName { get; set; }
}

[DataContract(Namespace = ...........)]
interface IVesselSequence
{
[DataMember]
int AllocationId { get; set; }
[DataMember]
string ScenarioName { get; set; }
}

关于c# - WCF DataContract 与 DataContract 接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1090736/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com