0

I have an appsettings.json file in my C# app. It contains field with names in upper case:

{
    "FIELD_ONE": "foo",
    "FIELD_TWO": "bar"
}

But I would like to bind it to class with camel-case naming style:

public class MySettings
{
    public string FieldOne { get; set; }
    public string FieldTwo { get; set; }
}

How can I bind this appsettings to MySettings instance?

1
  • You might have to do it manually - FieldOne = config.GetValue<string>("FIELD_ONE") Commented Sep 30, 2021 at 16:06

1 Answer 1

1

This could be a solution:

public class MySettings
{
     [JsonProperty("FIELD_ONE")]
     public string FieldOne { get; set; }
     [JsonProperty("FIELD_TWO")]
     public string FieldTwo { get; set; }
}
Sign up to request clarification or add additional context in comments.

4 Comments

does not work for me
and what about this? public string FIELD_ONE { get; set; } public string FIELD_TWO { get; set; }
it works but I would like to use camel-case in my class
I think it's impossible but I'm not sure

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.