简体   繁体   中英

Map class property name in C#

I am sending to Azure Mobile Service Custom API method some information - object of class AddFriendRequest.

public class AddFriendRequest
{
    public string token { get; set; }
    public string uuid { get; set; }
}

Now I would like to change property 'token' to 'MY-TOKEN'. What I should use to change that property name without changing class object name, something like:

public class AddFriendRequest
{
    ["MY-TOKEN"]
    public string token { get; set; }
    public string uuid { get; set; }
} 

Depending on the method of serialization you could use the data contract:

[DataContract]
public class AddFriendRequest
{
    [DataMember(Name="MY-TOKEN")]
    public string token { get; set; }
    [DataMember]
    public string uuid { get; set; }
} 

I'm not sure if it is wise to have a hyphon in the name of a property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM