c# – WCF DataContract vs DataContract接口

前端之家收集整理的这篇文章主要介绍了c# – WCF DataContract vs DataContract接口前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
新的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#相关文章