인터페이스 구성원에 DataMemberAttribute을 넣는 것은 무엇을 의미합니까? 파생 클래스에 어떤 영향을 줍니까?DataMemberAttribute를 인터페이스 멤버에 두는 것은 무엇을 의미합니까?
8
A
답변
9
는 DataMember를 속성은 당신이 구현하는 클래스를 장식해야합니다으로이 속성 인터페이스 멤버를 장식하는 거의 의미가,
[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, Inherited = false,
AllowMultiple = false)]
public sealed class DataMemberAttribute : Attribute
따라서 상속하지 않습니다 '이 속성이있는 회원도 있습니다.
-1
[DataMember] 특성은 유형의 멤버에 적용될 때 멤버가 데이터 계약의 일부임을 지정합니다. 이 특성을 필드 또는 속성에 명시 적으로 적용하면 DataContractSerializer 개체 (Article에서 가져옴)에서 멤버 값을 serialize하도록 지정합니다.
1
이 경우 내 WCF 서비스에서이 특성을 사용합니다. 나는 WCF WebService를위한 인터페이스를 만들 때 나는이 방법으로 인터페이스를 정의 할 : 당신이 볼 수 있듯이
Imports System.ServiceModel
<ServiceContract()>
Public Interface IClientContract
<OperationContract()>
Function GetClientList() As IList(Of POCOClients)
End Interface
는이 서비스의 example.com의 clien은 POCOCLient 수업을 받게됩니다. 그런 다음 클래스가 올바르게 serialize되고 vaa WCF를 전송할 수 있도록 양식에 요청하는 특성으로 POCOClient 클래스를 꾸밀 필요가 있습니다. 다음 서명에 나타낸 바와 같이
<DataContract()>
<MetadataType(GetType(POCOAuthorizedkeys.POCOAuthorizedkeysMetaData))>
Public Class POCOAuthorizedkeys
<DataMember()>
<DisplayName("Id")>
Public Property Id As Integer
<DataMember()>
<DisplayName("IdPackage")>
Public Property IdPackage As Integer
<DataMember()>
<DisplayName("AuthorizedKey")>
Public Property AuthorizedKey As String
<DataMember()>
<DisplayName("IdUnthrustedClient")>
Public Property IdUnthrustedClient As Nullable(Of Integer)
End Class
+1
신뢰할 수없는 클라이언트는 최악입니다. – stuartd
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx –