Click here to Skip to main content
15,921,203 members
Home / Discussions / C#
   

C#

 
Questionlast 3 numbers Pin
_Q12_17-Apr-19 12:04
_Q12_17-Apr-19 12:04 
AnswerRe: last 3 numbers Pin
Gerry Schmitz17-Apr-19 13:05
mveGerry Schmitz17-Apr-19 13:05 
GeneralRe: last 3 numbers Pin
_Q12_17-Apr-19 13:36
_Q12_17-Apr-19 13:36 
AnswerRe: last 3 numbers Pin
Luc Pattyn17-Apr-19 13:11
sitebuilderLuc Pattyn17-Apr-19 13:11 
AnswerRe: last 3 numbers Pin
#realJSOP18-Apr-19 2:04
professional#realJSOP18-Apr-19 2:04 
AnswerRe: last 3 numbers Pin
BillWoodruff18-Apr-19 20:57
professionalBillWoodruff18-Apr-19 20:57 
QuestionWCF Pin
Member 1406752317-Apr-19 4:12
Member 1406752317-Apr-19 4:12 
AnswerRe: WCF Pin
#realJSOP17-Apr-19 4:25
professional#realJSOP17-Apr-19 4:25 
QuestionReferencing Dynamic Control Array Data Pin
Member 1427108416-Apr-19 12:11
Member 1427108416-Apr-19 12:11 
AnswerRe: Referencing Dynamic Control Array Data Pin
Member 1427108416-Apr-19 15:38
Member 1427108416-Apr-19 15:38 
SuggestionRe: Referencing Dynamic Control Array Data Pin
Richard Deeming17-Apr-19 1:07
mveRichard Deeming17-Apr-19 1:07 
AnswerRe: Referencing Dynamic Control Array Data Pin
BillWoodruff16-Apr-19 16:29
professionalBillWoodruff16-Apr-19 16:29 
AnswerRe: Referencing Dynamic Control Array Data Pin
OriginalGriff16-Apr-19 21:22
mveOriginalGriff16-Apr-19 21:22 
QuestionJson formatting using an object in c# Pin
ATLDev15-Apr-19 11:52
ATLDev15-Apr-19 11:52 
AnswerRe: Json formatting using an object in c# Pin
OriginalGriff15-Apr-19 21:21
mveOriginalGriff15-Apr-19 21:21 
GeneralRe: Json formatting using an object in c# Pin
Rob Philpott16-Apr-19 6:21
Rob Philpott16-Apr-19 6:21 
AnswerRe: Json formatting using an object in c# Pin
Richard Deeming16-Apr-19 7:47
mveRichard Deeming16-Apr-19 7:47 
If you're using JSON.NET[^], you can use the JsonProperty attribute[^] to control the property names. For example:
C#
public class IsoDateTimeFormatConverter : IsoDateTimeConverter
{
    public IsoDateTimeFormatConverter(string format)
    {
        DateTimeFormat = format;
    }
}

public class CustomFields
{
    [JsonProperty("post-date")]
    [JsonConverter(typeof(IsoDateTimeFormatConverter), "yyyy-MM-dd")]
    public DateTimeOffset PostDate { get; set; }
}

public class Root
{
    [JsonProperty("custom-fields")]
    public CustomFields CustomFields { get; } = new CustomFields();
}

...

var x = new Root
{
    CustomFields = 
    {
        PostDate = DateTime.Today
    }
};

string json = JsonConvert.SerializeObject(x);
// Output: {"custom-fields":{"post-date":"2019-04-16"}}

If the custom fields are dynamic, then you could use a dictionary:
C#
public class Root
{
    [JsonProperty("custom-fields")]
    public Dictionary<string, object> CustomFields { get; } = new Dictionary<string, object>();
}

...

var x = new Root
{
    CustomFields = 
    {
        ["post-date"] = DateTime.Today.ToString("yyyy-MM-dd")
    }
};

string json = JsonConvert.SerializeObject(x);
// Output: {"custom-fields":{"post-date":"2019-04-16"}}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Json formatting using an object in c# Pin
ATLDev18-Apr-19 6:08
ATLDev18-Apr-19 6:08 
GeneralRe: Json formatting using an object in c# Pin
Richard Deeming18-Apr-19 7:30
mveRichard Deeming18-Apr-19 7:30 
QuestionHow to fill between two spline curves with two different colors in C# Pin
Member 1332584612-Apr-19 10:01
Member 1332584612-Apr-19 10:01 
AnswerRe: How to fill between two spline curves with two different colors in C# Pin
Gerry Schmitz13-Apr-19 5:49
mveGerry Schmitz13-Apr-19 5:49 
AnswerRe: How to fill between two spline curves with two different colors in C# Pin
jschell13-Apr-19 6:17
jschell13-Apr-19 6:17 
AnswerRe: How to fill between two spline curves with two different colors in C# Pin
RodStephens13-Apr-19 6:40
RodStephens13-Apr-19 6:40 
QuestionTalk Over Mic To Remote PCs Pin
Kevin Marois11-Apr-19 10:57
professionalKevin Marois11-Apr-19 10:57 
AnswerRe: Talk Over Mic To Remote PCs Pin
Richard MacCutchan11-Apr-19 20:30
mveRichard MacCutchan11-Apr-19 20:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.