Overwrite Json property name in c#

前端 未结 2 836
野的像风
野的像风 2020-12-01 21:52

I have a class with following fields. Those properties are used to serialize as json object when it needs to call a external rest API method.

public class C         


        
2条回答
  •  被撕碎了的回忆
    2020-12-01 22:36

    Define different configuration modes like Debug/Release/QA/Staging

    Then add compilation symbols for each one of them. and in your code you do something like:

    Following I suppose you defined: QA and STAGING

    public class Customer
    {
    
        [JsonProperty(PropertyName = "email")]          
        public string Email { get; set; }
    
        #if QA
            [JsonProperty(PropertyName = "prop[QA_ID]")]
        #elif STAGING
            [JsonProperty(PropertyName = "prop[STAGING_ID]")]
        #endif
        public string Test{ get; set; }
    
        // there are lot of properties 
    }
    

    You can use these configuration for automated deploy too which will save you time.

提交回复
热议问题