Skip to content

Commit 7d99784

Browse files
authored
Merge pull request #15 from nblumhardt/fixoverloadselection
Choose overloads based on matching parameter count
2 parents 88ef290 + f8b76eb commit 7d99784

File tree

9 files changed

+163
-45
lines changed

9 files changed

+163
-45
lines changed

Build.ps1

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,51 @@
1+
echo "build: Build started"
2+
13
Push-Location $PSScriptRoot
24

3-
if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
5+
if(Test-Path .\artifacts) {
6+
echo "build: Cleaning .\artifacts"
7+
Remove-Item .\artifacts -Force -Recurse
8+
}
49

510
& dotnet restore --no-cache
611

712
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
813
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
9-
$suffix = @{ $true = ""; $false = "$branch-$revision"}[$branch -eq "master" -and $revision -ne "local"]
14+
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]
1015

11-
foreach ($src in ls src/Serilog.*) {
16+
echo "build: Version suffix is $suffix"
17+
18+
foreach ($src in ls src/*) {
1219
Push-Location $src
1320

14-
& dotnet pack -c Release -o ..\..\.\artifacts --version-suffix=$suffix
21+
echo "build: Packaging project in $src"
22+
23+
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
1524
if($LASTEXITCODE -ne 0) { exit 1 }
1625

1726
Pop-Location
1827
}
1928

20-
foreach ($test in ls test/Serilog.*.Tests) {
29+
foreach ($test in ls test/*.PerformanceTests) {
2130
Push-Location $test
2231

23-
& dotnet test -c Release
32+
echo "build: Building performance test project in $test"
33+
34+
& dotnet build -c Release
2435
if($LASTEXITCODE -ne 0) { exit 2 }
2536

2637
Pop-Location
2738
}
2839

40+
foreach ($test in ls test/*.Tests) {
41+
Push-Location $test
42+
43+
echo "build: Testing project in $test"
44+
45+
& dotnet test -c Release
46+
if($LASTEXITCODE -ne 0) { exit 3 }
47+
48+
Pop-Location
49+
}
50+
2951
Pop-Location

sample/Sample/project.lock.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,13 +2349,12 @@
23492349
"lib/netstandard1.3/_._": {}
23502350
}
23512351
},
2352-
"Serilog.Settings.Configuration/2.0.0-rc": {
2352+
"Serilog.Settings.Configuration/2.1.0": {
23532353
"type": "project",
23542354
"framework": ".NETStandard,Version=v1.6",
23552355
"dependencies": {
23562356
"Microsoft.Extensions.Configuration.Abstractions": "1.0.0",
23572357
"Microsoft.Extensions.DependencyModel": "1.0.0",
2358-
"Newtonsoft.Json": "9.0.1",
23592358
"Serilog": "2.0.0"
23602359
},
23612360
"compile": {
@@ -2673,13 +2672,12 @@
26732672
"lib/net45/_._": {}
26742673
}
26752674
},
2676-
"Serilog.Settings.Configuration/2.0.0-rc": {
2675+
"Serilog.Settings.Configuration/2.1.0": {
26772676
"type": "project",
26782677
"framework": ".NETFramework,Version=v4.5.1",
26792678
"dependencies": {
26802679
"Microsoft.Extensions.Configuration.Abstractions": "1.0.0",
26812680
"Microsoft.Extensions.DependencyModel": "1.0.0",
2682-
"Newtonsoft.Json": "9.0.1",
26832681
"Serilog": "2.0.0",
26842682
"System.Runtime": "4.0.10"
26852683
},
@@ -7561,7 +7559,7 @@
75617559
"ref/xamarinwatchos10/_._"
75627560
]
75637561
},
7564-
"Serilog.Settings.Configuration/2.0.0-rc": {
7562+
"Serilog.Settings.Configuration/2.1.0": {
75657563
"type": "project",
75667564
"path": "../../src/Serilog.Settings.Configuration/project.json",
75677565
"msbuildProject": "../../src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.xproj"

src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ static void CallConfigurationMethods(Dictionary<string, Dictionary<string, strin
179179
{
180180
foreach (var method in methods)
181181
{
182-
var methodInfo = configurationMethods
183-
.Where(m => m.Name == method.Key && m.GetParameters().Skip(1).All(p => p.HasDefaultValue || method.Value.Any(s => s.Key == p.Name)))
184-
.OrderByDescending(m => m.GetParameters().Length)
185-
.FirstOrDefault();
182+
var methodInfo = SelectConfigurationMethod(configurationMethods, method.Key, method.Value);
186183

187184
if (methodInfo != null)
188185
{
@@ -197,6 +194,15 @@ static void CallConfigurationMethods(Dictionary<string, Dictionary<string, strin
197194
}
198195
}
199196

197+
internal static MethodInfo SelectConfigurationMethod(IEnumerable<MethodInfo> candidateMethods, string name, Dictionary<string, string> suppliedArgumentValues)
198+
{
199+
return candidateMethods
200+
.Where(m => m.Name == name &&
201+
m.GetParameters().Skip(1).All(p => p.HasDefaultValue || suppliedArgumentValues.Any(s => s.Key == p.Name)))
202+
.OrderByDescending(m => m.GetParameters().Count(p => suppliedArgumentValues.Any(s => s.Key == p.Name)))
203+
.FirstOrDefault();
204+
}
205+
200206
static readonly Dictionary<Type, Func<string, object>> ExtendedTypeConversions = new Dictionary<Type, Func<string, object>>
201207
{
202208
{ typeof(Uri), s => new Uri(s) },

src/Serilog.Settings.Configuration/project.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"iconUrl": "http://serilog.net/images/serilog-configuration-nuget.png"
1010
},
1111
"dependencies": {
12-
"Newtonsoft.Json": "9.0.1",
1312
"Microsoft.Extensions.Configuration.Abstractions": "1.0.0",
1413
"Microsoft.Extensions.DependencyModel": "1.0.0",
1514
"Serilog": "2.0.0"

src/Serilog.Settings.Configuration/project.lock.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3037,7 +3037,6 @@
30373037
"": [
30383038
"Microsoft.Extensions.Configuration.Abstractions >= 1.0.0",
30393039
"Microsoft.Extensions.DependencyModel >= 1.0.0",
3040-
"Newtonsoft.Json >= 9.0.1",
30413040
"Serilog >= 2.0.0"
30423041
],
30433042
".NETFramework,Version=v4.5.1": [
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.Collections.Generic;
2+
using Serilog.Settings.Configuration;
3+
using Serilog.Formatting;
4+
using Serilog.Formatting.Json;
5+
using Xunit;
6+
using System.Reflection;
7+
using System.Linq;
8+
9+
namespace Serilog.Settings.Configuration.Tests
10+
{
11+
public class ConfigurationReaderTests
12+
{
13+
[Fact]
14+
public void StringValuesConvertToDefaultInstancesIfTargetIsInterface()
15+
{
16+
var result = ConfigurationReader.ConvertToType("Serilog.Formatting.Json.JsonFormatter, Serilog", typeof(ITextFormatter));
17+
Assert.IsType<JsonFormatter>(result);
18+
}
19+
20+
[Fact]
21+
public void CallableMethodsAreSelected()
22+
{
23+
var options = typeof(DummyLoggerConfigurationExtensions).GetTypeInfo().DeclaredMethods.ToList();
24+
Assert.Equal(2, options.Count(mi => mi.Name == "DummyRollingFile"));
25+
var suppliedArguments = new Dictionary<string, string>
26+
{
27+
{"pathFormat", "C:\\" }
28+
};
29+
30+
var selected = ConfigurationReader.SelectConfigurationMethod(options, "DummyRollingFile", suppliedArguments);
31+
Assert.Equal(typeof(string), selected.GetParameters()[1].ParameterType);
32+
}
33+
34+
[Fact]
35+
public void MethodsAreSelectedBasedOnCountOfMatchedArguments()
36+
{
37+
var options = typeof(DummyLoggerConfigurationExtensions).GetTypeInfo().DeclaredMethods.ToList();
38+
Assert.Equal(2, options.Count(mi => mi.Name == "DummyRollingFile"));
39+
var suppliedArguments = new Dictionary<string, string>()
40+
{
41+
{ "pathFormat", "C:\\" },
42+
{ "formatter", "SomeFormatter, SomeAssembly" }
43+
};
44+
45+
var selected = ConfigurationReader.SelectConfigurationMethod(options, "DummyRollingFile", suppliedArguments);
46+
Assert.Equal(typeof(ITextFormatter), selected.GetParameters()[1].ParameterType);
47+
}
48+
}
49+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using Serilog.Configuration;
3+
using Serilog.Events;
4+
using Serilog.Formatting;
5+
6+
namespace Serilog.Settings.Configuration.Tests
7+
{
8+
static class DummyLoggerConfigurationExtensions
9+
{
10+
public static LoggerConfiguration DummyRollingFile(
11+
LoggerSinkConfiguration loggerSinkConfiguration,
12+
string pathFormat,
13+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
14+
string outputTemplate = null,
15+
IFormatProvider formatProvider = null)
16+
{
17+
return null;
18+
}
19+
20+
public static LoggerConfiguration DummyRollingFile(
21+
LoggerSinkConfiguration loggerSinkConfiguration,
22+
ITextFormatter formatter,
23+
string pathFormat,
24+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
25+
{
26+
return null;
27+
}
28+
}
29+
}

test/Serilog.Settings.Configuration.Tests/project.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
"dependencies": {
44
"Serilog.Settings.Configuration": { "target": "project" },
55
"xunit": "2.1.0",
6-
"dotnet-test-xunit": "1.0.0-rc3-build10026"
6+
"dotnet-test-xunit": "1.0.0-rc2-build10025"
77
},
88
"buildOptions": {
99
"keyFile": "../../assets/Serilog.snk"
1010
},
1111
"frameworks": {
12-
"net4.6": {
13-
"dependencies": {
14-
"Microsoft.NETCore.Platforms": "1.0.1"
15-
}
16-
},
12+
"net4.5.2": {},
1713
"netcoreapp1.0": {
1814
"dependencies": {
1915
"Microsoft.NETCore.App": {

test/Serilog.Settings.Configuration.Tests/project.lock.json

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": 2,
44
"targets": {
55
".NETCoreApp,Version=v1.0": {
6-
"dotnet-test-xunit/1.0.0-rc3-build10026": {
6+
"dotnet-test-xunit/1.0.0-rc2-build10025": {
77
"type": "package",
88
"dependencies": {
99
"Microsoft.Extensions.Testing.Abstractions": "1.0.0-preview1-002702",
@@ -2630,13 +2630,12 @@
26302630
"lib/dotnet/xunit.runner.utility.dotnet.dll": {}
26312631
}
26322632
},
2633-
"Serilog.Settings.Configuration/2.0.0-rc": {
2633+
"Serilog.Settings.Configuration/2.1.0": {
26342634
"type": "project",
26352635
"framework": ".NETStandard,Version=v1.6",
26362636
"dependencies": {
26372637
"Microsoft.Extensions.Configuration.Abstractions": "1.0.0",
26382638
"Microsoft.Extensions.DependencyModel": "1.0.0",
2639-
"Newtonsoft.Json": "9.0.1",
26402639
"Serilog": "2.0.0"
26412640
},
26422641
"compile": {
@@ -2647,8 +2646,8 @@
26472646
}
26482647
}
26492648
},
2650-
".NETFramework,Version=v4.6": {
2651-
"dotnet-test-xunit/1.0.0-rc3-build10026": {
2649+
".NETFramework,Version=v4.5.2": {
2650+
"dotnet-test-xunit/1.0.0-rc2-build10025": {
26522651
"type": "package",
26532652
"dependencies": {
26542653
"Microsoft.Extensions.Testing.Abstractions": "1.0.0-preview1-002702",
@@ -2796,15 +2795,15 @@
27962795
"lib/net451/Microsoft.Extensions.Testing.Abstractions.dll": {}
27972796
}
27982797
},
2799-
"Microsoft.NETCore.Platforms/1.0.1": {
2798+
"Microsoft.NETCore.Platforms/1.0.1-rc2-24027": {
28002799
"type": "package",
2801-
"compile": {
2802-
"lib/netstandard1.0/_._": {}
2803-
},
2804-
"runtime": {
2805-
"lib/netstandard1.0/_._": {}
2800+
"dependencies": {
2801+
"Microsoft.NETCore.Targets": "1.0.1-rc2-24027"
28062802
}
28072803
},
2804+
"Microsoft.NETCore.Targets/1.0.1-rc2-24027": {
2805+
"type": "package"
2806+
},
28082807
"Newtonsoft.Json/9.0.1": {
28092808
"type": "package",
28102809
"compile": {
@@ -3051,13 +3050,12 @@
30513050
"lib/net35/xunit.runner.utility.desktop.dll": {}
30523051
}
30533052
},
3054-
"Serilog.Settings.Configuration/2.0.0-rc": {
3053+
"Serilog.Settings.Configuration/2.1.0": {
30553054
"type": "project",
30563055
"framework": ".NETFramework,Version=v4.5.1",
30573056
"dependencies": {
30583057
"Microsoft.Extensions.Configuration.Abstractions": "1.0.0",
30593058
"Microsoft.Extensions.DependencyModel": "1.0.0",
3060-
"Newtonsoft.Json": "9.0.1",
30613059
"Serilog": "2.0.0",
30623060
"System.Runtime": "4.0.10"
30633061
},
@@ -3071,12 +3069,12 @@
30713069
}
30723070
},
30733071
"libraries": {
3074-
"dotnet-test-xunit/1.0.0-rc3-build10026": {
3075-
"sha512": "/gFzS3wkG+QepAkPJ4Q3vOKULtBh1fHd2WV7Ed6IAuKevE1x2JorVkIyzAQI3lc6B6wwlXWhyXb6aWVoICFg+g==",
3072+
"dotnet-test-xunit/1.0.0-rc2-build10025": {
3073+
"sha512": "MhxfSjj6z/dpct/9zsssDAXKxWXhAx9s39080Qm+59k2vLJafUjUTzl4cs2rKHK7BYty2EyNxir68v7cJcaBEA==",
30763074
"type": "package",
3077-
"path": "dotnet-test-xunit/1.0.0-rc3-build10026",
3075+
"path": "dotnet-test-xunit/1.0.0-rc2-build10025",
30783076
"files": [
3079-
"dotnet-test-xunit.1.0.0-rc3-build10026.nupkg.sha512",
3077+
"dotnet-test-xunit.1.0.0-rc2-build10025.nupkg.sha512",
30803078
"dotnet-test-xunit.nuspec",
30813079
"lib/net451/dotnet-test-xunit.exe",
30823080
"lib/netcoreapp1.0/dotnet-test-xunit.dll",
@@ -3375,6 +3373,18 @@
33753373
"runtime.json"
33763374
]
33773375
},
3376+
"Microsoft.NETCore.Platforms/1.0.1-rc2-24027": {
3377+
"sha512": "BIZpJMovdHgUbCrZR9suwwLpZMNehIkaFKiIb9X5+wPjXNHMSQ91ETSASAnEXERyU7+ptJAfJGqgr3Y9ly98MQ==",
3378+
"type": "package",
3379+
"path": "Microsoft.NETCore.Platforms/1.0.1-rc2-24027",
3380+
"files": [
3381+
"Microsoft.NETCore.Platforms.1.0.1-rc2-24027.nupkg.sha512",
3382+
"Microsoft.NETCore.Platforms.nuspec",
3383+
"ThirdPartyNotices.txt",
3384+
"dotnet_library_license.txt",
3385+
"runtime.json"
3386+
]
3387+
},
33783388
"Microsoft.NETCore.Platforms/1.0.1": {
33793389
"sha512": "2G6OjjJzwBfNOO8myRV/nFrbTw5iA+DEm0N+qUqhrOmaVtn4pC77h38I1jsXGw5VH55+dPfQsqHD0We9sCl9FQ==",
33803390
"type": "package",
@@ -3400,6 +3410,18 @@
34003410
"runtime.json"
34013411
]
34023412
},
3413+
"Microsoft.NETCore.Targets/1.0.1-rc2-24027": {
3414+
"sha512": "pNy4HhkgeM1kE/IqtDQLfUcMpy3NB3B/p8J/71G9Wvu2p/ARRH2hjq1TkETiqQW7ER9aFUs86wmgHyk3dtDgVQ==",
3415+
"type": "package",
3416+
"path": "Microsoft.NETCore.Targets/1.0.1-rc2-24027",
3417+
"files": [
3418+
"Microsoft.NETCore.Targets.1.0.1-rc2-24027.nupkg.sha512",
3419+
"Microsoft.NETCore.Targets.nuspec",
3420+
"ThirdPartyNotices.txt",
3421+
"dotnet_library_license.txt",
3422+
"runtime.json"
3423+
]
3424+
},
34033425
"Microsoft.NETCore.Targets/1.0.1": {
34043426
"sha512": "rkn+fKobF/cbWfnnfBOQHKVKIOpxMZBvlSHkqDWgBpwGDcLRduvs3D9OLGeV6GWGvVwNlVi2CBbTjuPmtHvyNw==",
34053427
"type": "package",
@@ -8176,7 +8198,7 @@
81768198
"xunit.runner.utility.nuspec"
81778199
]
81788200
},
8179-
"Serilog.Settings.Configuration/2.0.0-rc": {
8201+
"Serilog.Settings.Configuration/2.1.0": {
81808202
"type": "project",
81818203
"path": "../../src/Serilog.Settings.Configuration/project.json",
81828204
"msbuildProject": "../../src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.xproj"
@@ -8185,15 +8207,13 @@
81858207
"projectFileDependencyGroups": {
81868208
"": [
81878209
"Serilog.Settings.Configuration",
8188-
"dotnet-test-xunit >= 1.0.0-rc3-build10026",
8210+
"dotnet-test-xunit >= 1.0.0-rc2-build10025",
81898211
"xunit >= 2.1.0"
81908212
],
81918213
".NETCoreApp,Version=v1.0": [
81928214
"Microsoft.NETCore.App >= 1.0.0"
81938215
],
8194-
".NETFramework,Version=v4.6": [
8195-
"Microsoft.NETCore.Platforms >= 1.0.1"
8196-
]
8216+
".NETFramework,Version=v4.5.2": []
81978217
},
81988218
"tools": {},
81998219
"projectFileToolGroups": {}

0 commit comments

Comments
 (0)