Skip to content

Commit e0defd9

Browse files
committed
avoid load type in ResolveDictionaryKey
1 parent 2e83808 commit e0defd9

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/Verify/Serialization/CustomContractResolver_Dictionary.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
protected override JsonDictionaryContract CreateDictionaryContract(Type objectType)
44
{
55
var contract = base.CreateDictionaryContract(objectType);
6-
contract.DictionaryKeyResolver = (_, name, original) => ResolveDictionaryKey(contract, name, original);
6+
contract.DictionaryKeyResolver = (_, name, original) => ResolveDictionaryKey(name, original);
77
if (settings.SortDictionaries)
88
{
99
contract.OrderByKey = true;
@@ -41,10 +41,9 @@ static KeyValueInterceptResult ToInterceptKeyValueResult(ScrubOrIgnore scrubOrIg
4141
return KeyValueInterceptResult.ReplaceValue("{Scrubbed}");
4242
}
4343

44-
string ResolveDictionaryKey(JsonDictionaryContract contract, string name, object original)
44+
string ResolveDictionaryKey(string name, object original)
4545
{
4646
var counter = Counter.Current;
47-
var keyType = contract.DictionaryKeyType;
4847

4948
#if NET6_0_OR_GREATER
5049

@@ -98,14 +97,8 @@ string ResolveDictionaryKey(JsonDictionaryContract contract, string name, object
9897
}
9998
}
10099

101-
if (keyType == typeof(Type))
100+
if (original is Type type)
102101
{
103-
var type = Type.GetType(name);
104-
if (type is null)
105-
{
106-
throw new($"Could not load type `{name}`.");
107-
}
108-
109102
return type.SimpleName();
110103
}
111104

0 commit comments

Comments
 (0)