Skip to content

Commit db533a5

Browse files
committed
Minor improvements to TextBuilderType setter
1 parent 079a950 commit db533a5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

source/FileLogger/LogFileSettings.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public interface ILogFileSettings : ILogFileSettingsBase
4242

4343
public abstract class LogFileSettingsBase : ILogFileSettingsBase
4444
{
45-
private static ConcurrentDictionary<Type, IFileLogEntryTextBuilder> TextBuilderCache =>
45+
private static ConcurrentDictionary<Type, IFileLogEntryTextBuilder> TextBuilderInstances =>
4646
LazyInitializer.EnsureInitialized(ref field, () => new ConcurrentDictionary<Type, IFileLogEntryTextBuilder>())!;
4747

4848
public LogFileSettingsBase() { }
@@ -99,12 +99,12 @@ public string? TextBuilderType
9999

100100
// it's important to return the same instance of a given text builder type
101101
// because FileLogger use the instance in its internal cache (FileGroups) as a part of the key
102-
TextBuilder = TextBuilderCache.GetOrAdd(type, type =>
102+
TextBuilder = TextBuilderInstances.GetOrAdd(type, type =>
103103
{
104-
if (!type.GetTypeInfo().ImplementedInterfaces.Contains(typeof(IFileLogEntryTextBuilder)))
104+
if (!typeof(IFileLogEntryTextBuilder).IsAssignableFrom(type))
105105
throw new ArgumentException(string.Format(provider: null, Resources.InterfaceNotImplemented, typeof(IFileLogEntryTextBuilder)), nameof(value));
106106

107-
ConstructorInfo ctor = type.GetTypeInfo().DeclaredConstructors.FirstOrDefault(ci => ci.GetParameters().Length == 0)
107+
ConstructorInfo ctor = type.GetTypeInfo().GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, binder: null, Type.EmptyTypes, modifiers: null)
108108
?? throw new ArgumentException(Resources.ParameterlessCtorNotProvided, nameof(value));
109109

110110
return (IFileLogEntryTextBuilder)ctor.Invoke(null);

0 commit comments

Comments
 (0)