Skip to content

Instantly share code, notes, and snippets.

@adams85
Last active September 19, 2018 16:42
Show Gist options
  • Save adams85/662ac5d2a03f236dc73f00bbfd9aebf8 to your computer and use it in GitHub Desktop.
Save adams85/662ac5d2a03f236dc73f00bbfd9aebf8 to your computer and use it in GitHub Desktop.
{
"PhoneBookSection": {
"John Doe": "555-123-456",
"Jane Doe": "555-234-567"
}
}
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
namespace Sample
{
class Program
{
static readonly IConfiguration Configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
.Build();
static void Main(string[] args)
{
const string PhoneBookSection = "PhoneBookSection";
var phonebook = new Dictionary<string, string>();
Configuration.Bind(PhoneBookSection, phonebook);
foreach (var entry in phonebook)
Console.WriteLine($"{entry.Key} - {entry.Value}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment