0

I have the following code preparing a dictionary before inserting into MemoryConfigurationSource

 var clientConfigurations = await httpClient.GetFromJsonAsync<ClientConfigurations>("api/ClientConfiguration");

 var clientConfigurationsDictionary = new Dictionary<string, string>()
 {
      { "AzureAd:Authority", clientConfigurations.AzureAd.Authority },
      { "AzureAd:ClientId", clientConfigurations.AzureAd.ClientId },
      { "AzureAd:ValidateAuthority", $"{clientConfigurations.AzureAd.ValidateAuthority}" },
      { "AccessTokenScope", clientConfigurations.AccessTokenScope }

     };

 var memoryConfig = new MemoryConfigurationSource { InitialData = clientConfigurationsDictionary };

I want to make the second line a generic method that takes a class and returns a dictionary. Hoping to not reinvent to wheel by doing this myself via reflection. I'm looking for a library utility that already does this.

Note: the compound value of ClientConfigurations.AzureAd.Authority is broken down to "AzureAd:Authority".

Brian Parker
  • 11,946
  • 2
  • 31
  • 41

0 Answers0