Deserialize datamember multiple names

前端 未结 1 448
时光取名叫无心
时光取名叫无心 2021-01-24 18:51

I have this filed named 1_method

public class DerivedClass
{

    [DataMember(Name=\"1_method\")]
    public virtual string FirstMethod { get; protected set; }

         


        
相关标签:
1条回答
  • 2021-01-24 19:26

    as far as i have worked out, you cant have multiple names for datamember attributes, you just have to use the same internal variable for storage.

    public class DerivedClass
    {
       string _internal;
       [DataMember(Name="1_method")]
       public virtual string FirstMethod { 
            get{
             return this._internal;
            }
            protected set {
             this._internal = value;
            }
       }
    
     [DataMember(Name="2_method")]
     public virtual string SecondMethod { 
            get{
             return this._internal;
            }
            protected set {
             this._internal = value;
            }
     }
    }
    
    0 讨论(0)
提交回复
热议问题