Skip to content

Commit

Permalink
Json configuration file name is case insensitive (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko committed Feb 16, 2021
1 parent b66f87e commit 9b01563
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Xml;
Expand Down Expand Up @@ -34,9 +35,17 @@ public JsonFileConfigurationProvider(string delimeter, string filePath, bool opt
{
var properties = new Dictionary<string, string>();

if (File.Exists(_filePath))
var directory = Path.GetDirectoryName(_filePath);

if (string.IsNullOrEmpty(directory)) directory = Directory.GetCurrentDirectory();

var files = Directory.GetFiles(directory);

var filePath = files.FirstOrDefault(f => f.ToUpperInvariant() == _filePath.ToUpperInvariant());

if (filePath != null)
{
var json = File.ReadAllText(_filePath);
var json = File.ReadAllText(filePath);

var flattenProperties = GetFlattenProperties(json);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void ShouldJsonFileNameBeCaseInsensitive()

File.WriteAllText(tempFile.ToLowerInvariant(), "{ \"a\": true }");

var config = new ConfigurationBuilder().AddJsonFile(tempFile.ToUpperInvariant()).Build();
var config = new ConfigurationBuilder().AddJsonFile(Path.Combine(Path.GetDirectoryName(tempFile), Path.GetFileName(tempFile).ToUpperInvariant())).Build();
config.GetValue<bool>("a").Should().BeTrue();
}

Expand Down

0 comments on commit 9b01563

Please sign in to comment.