将DataMemberAttribute放在接口成员上意味着什么?
将DataMemberAttribute放在接口成员上意味着什么? 这对派生类有何影响?
如以下签名所示,DataMember属性不可inheritance
[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, Inherited = false, AllowMultiple = false)] public sealed class DataMemberAttribute : Attribute
因此,使用此属性修饰接口成员几乎没有意义,因为您还必须使用此属性修饰实现类的成员。
就我而言,我将此属性与我的WCF服务一起使用。 当我为WCF Web服务创建一个接口时,我会以这种方式定义一个接口:
Imports System.ServiceModel Public Interface IClientContract Function GetClientList() As IList(Of POCOClients) End Interface
如您所见,此服务的客户将收到POCOCLient类。 然后我需要用这种方式用你要求表单的属性来装饰POCOClient类,以便让类正确地序列化并发送víaWCF。
Public Class POCOAuthorizedkeys Public Property Id As Integer Public Property IdPackage As Integer Public Property AuthorizedKey As String Public Property IdUnthrustedClient As Nullable(Of Integer) End Class
[DataMember]属性应用于类型成员时,指定该成员是数据协定的一部分。 当此属性显式应用于字段或属性时,它指定成员值将由DataContractSerializer对象序列化(取自文章 )
上述就是C#学习教程:将DataMemberAttribute放在接口成员上意味着什么?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/962443.html