2012-12-30 7 views

답변

8

DataContract을 사용하는 주된 이점은 XmlMediaTypeFormatterJsonMediaTypeFormatter에 대한 몇 가지 일반적인 일련 화 힌트에 대해 중복 된 특성을 피할 수 있다는 것입니다. 나는. 당신은 직렬화 될 모델의 특정 속성을 옵트 인/옵트 아웃 (opt-in/opt-out)하거나 속성의 이름을 바꾸고 양쪽 포맷터를 존중하도록 설정할 수 있습니다. 예를 들어

는 :

public class Sample { 
    public string PropOne {get;set;} 

    [XmlIgnore] 
    [JsonIgnore] 
    public string PropTwo {get;set;} 

    [JsonProperty(PropertyName = "NewName")] 
    [XmlElement("NewName")] 
    public string PropThree {get; set;} 
} 
:

[DataContract] 
public class Sample { 

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

    public string PropTwo {get;set;} 

    [DataMember(Name="NewName")] 
    public string PropThree {get; set;} 
} 

에 상당