-1

I'm using strongly typed settings in my .NET 6 Project.

I'm binding the appSettings via Hostbuilder's

.ConfigureServices((hostContext, services) =>
                        {
                            services.Configure<Settings.Settings>(hostContext.Configuration.GetSection(Settings.Settings.SectionName));

I am looking for a way to automatically generate either:

  1. The Json section in appsettings.json (or any other json) from my Settings.cs File or
  2. The Settings.cs from a json section.

Is there any way I could do this ? Or any other way that is smarter than copy-pasting the Settings.cs' Properties into the Json and editing ?

DaQookie
  • 31
  • 4
  • 1
    I don't understand your question. #1 makes no sense, and for #2 it looks like you're already creating a DI graph object `IOptions` from the specified configuration section. – gunr2171 May 20 '22 at 14:35
  • @gunr2171 I want to this in the editor while developing. Not during Runtime. – DaQookie May 20 '22 at 15:03

1 Answers1

1

As regards #2, you could use "Paste JSON as classes" (Edit -> Paste special -> Paste JSON as classes):

  1. First copy the section from appsettings.json
  2. Open a code file and insert the JSON content
  3. Adjust to your needs
Markus
  • 20,838
  • 4
  • 31
  • 55
  • This does what I want. Thanks. Any way to make this work for Sections or Entries instead of the whole JSON ? – DaQookie May 20 '22 at 15:06
  • @DaQookie just select the parts of the JSON that is relevant. However, some adjustments might be necessary, but it could be useful for large configs. – Markus May 20 '22 at 16:07