Skip to content

Commit 7f292f6

Browse files
markvinczeaustinlparker
authored andcommitted
Make the PropertyFetcher case insensitive (#49)
1 parent 5d9c340 commit 7f292f6

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/OpenTracing.Contrib.NetCore/Internal/PropertyFetcher.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// From https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
22

33
using System;
4+
using System.Linq;
45
using System.Reflection;
56

67
namespace OpenTracing.Contrib.NetCore.Internal
@@ -28,7 +29,8 @@ public object Fetch(object obj)
2829
if (objType != _expectedType)
2930
{
3031
TypeInfo typeInfo = objType.GetTypeInfo();
31-
_fetchForExpectedType = PropertyFetch.FetcherForProperty(typeInfo.GetDeclaredProperty(_propertyName));
32+
var propertyInfo = typeInfo.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, _propertyName, StringComparison.InvariantCultureIgnoreCase));
33+
_fetchForExpectedType = PropertyFetch.FetcherForProperty(propertyInfo);
3234
_expectedType = objType;
3335
}
3436
return _fetchForExpectedType.Fetch(obj);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using OpenTracing.Contrib.NetCore.Internal;
5+
using Xunit;
6+
7+
namespace OpenTracing.Contrib.NetCore.Tests.Internal
8+
{
9+
public class PropertyFetcherTest
10+
{
11+
public class TestClass
12+
{
13+
public string TestProperty { get; set; }
14+
}
15+
16+
[Fact]
17+
public void Fetch_NameNotFound_NullReturned()
18+
{
19+
var obj = new TestClass { TestProperty = "TestValue" };
20+
21+
var sut = new PropertyFetcher("DifferentProperty");
22+
23+
var result = sut.Fetch(obj);
24+
25+
Assert.Null(result);
26+
}
27+
28+
[Fact]
29+
public void Fetch_NameFound_ValueReturned()
30+
{
31+
var obj = new TestClass { TestProperty = "TestValue" };
32+
33+
var sut = new PropertyFetcher("TestProperty");
34+
35+
var result = sut.Fetch(obj);
36+
37+
Assert.Equal("TestValue", result);
38+
}
39+
40+
[Fact]
41+
public void Fetch_NameFoundDifferentCasing_ValueReturned()
42+
{
43+
var obj = new TestClass { TestProperty = "TestValue" };
44+
45+
var sut = new PropertyFetcher("testproperty");
46+
47+
var result = sut.Fetch(obj);
48+
49+
Assert.Equal("TestValue", result);
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)