diff --git a/src/libraries/Microsoft.Extensions.Configuration.Abstractions/ref/Microsoft.Extensions.Configuration.Abstractions.csproj b/src/libraries/Microsoft.Extensions.Configuration.Abstractions/ref/Microsoft.Extensions.Configuration.Abstractions.csproj
index 3e4c0cc8363b9..3354e28728535 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Abstractions/ref/Microsoft.Extensions.Configuration.Abstractions.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration.Abstractions/ref/Microsoft.Extensions.Configuration.Abstractions.csproj
@@ -1,6 +1,6 @@
- $(NetCoreAppCurrent);netstandard2.0;$(NetFrameworkMinimum)
+ $(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)
enable
@@ -9,8 +9,12 @@
-
-
+
+
+
+
+
+
diff --git a/src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/Microsoft.Extensions.Configuration.Abstractions.csproj b/src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/Microsoft.Extensions.Configuration.Abstractions.csproj
index 49aabd359e3fc..03f61f772b639 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/Microsoft.Extensions.Configuration.Abstractions.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/Microsoft.Extensions.Configuration.Abstractions.csproj
@@ -1,7 +1,7 @@
- $(NetCoreAppCurrent);netstandard2.0;$(NetFrameworkMinimum)
+ $(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)
enable
true
diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/ref/Microsoft.Extensions.Configuration.Binder.cs b/src/libraries/Microsoft.Extensions.Configuration.Binder/ref/Microsoft.Extensions.Configuration.Binder.cs
index 30cdeda1b712d..efcb740d6663b 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Binder/ref/Microsoft.Extensions.Configuration.Binder.cs
+++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/ref/Microsoft.Extensions.Configuration.Binder.cs
@@ -15,26 +15,26 @@ public BinderOptions() { }
public static partial class ConfigurationBinder
{
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Cannot statically analyze the type of instance so its members may be trimmed")]
- public static void Bind(this Microsoft.Extensions.Configuration.IConfiguration configuration, object instance) { }
+ public static void Bind(this Microsoft.Extensions.Configuration.IConfiguration configuration, object? instance) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Cannot statically analyze the type of instance so its members may be trimmed")]
- public static void Bind(this Microsoft.Extensions.Configuration.IConfiguration configuration, object instance, System.Action configureOptions) { }
+ public static void Bind(this Microsoft.Extensions.Configuration.IConfiguration configuration, object? instance, System.Action? configureOptions) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Cannot statically analyze the type of instance so its members may be trimmed")]
- public static void Bind(this Microsoft.Extensions.Configuration.IConfiguration configuration, string key, object instance) { }
+ public static void Bind(this Microsoft.Extensions.Configuration.IConfiguration configuration, string key, object? instance) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.")]
- public static object Get(this Microsoft.Extensions.Configuration.IConfiguration configuration, System.Type type) { throw null; }
+ public static object? Get(this Microsoft.Extensions.Configuration.IConfiguration configuration, System.Type type) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.")]
- public static object Get(this Microsoft.Extensions.Configuration.IConfiguration configuration, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, System.Action configureOptions) { throw null; }
+ public static object? Get(this Microsoft.Extensions.Configuration.IConfiguration configuration, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, System.Action? configureOptions) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.")]
- public static object GetValue(this Microsoft.Extensions.Configuration.IConfiguration configuration, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, string key) { throw null; }
+ public static object? GetValue(this Microsoft.Extensions.Configuration.IConfiguration configuration, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, string key) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.")]
- public static object GetValue(this Microsoft.Extensions.Configuration.IConfiguration configuration, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, string key, object defaultValue) { throw null; }
+ public static object? GetValue(this Microsoft.Extensions.Configuration.IConfiguration configuration, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, string key, object defaultValue) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.")]
- public static T GetValue<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] T>(this Microsoft.Extensions.Configuration.IConfiguration configuration, string key) { throw null; }
+ public static T? GetValue<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] T>(this Microsoft.Extensions.Configuration.IConfiguration configuration, string key) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.")]
- public static T GetValue<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] T>(this Microsoft.Extensions.Configuration.IConfiguration configuration, string key, T defaultValue) { throw null; }
+ public static T? GetValue<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] T>(this Microsoft.Extensions.Configuration.IConfiguration configuration, string key, T defaultValue) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.")]
- public static T Get<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] T>(this Microsoft.Extensions.Configuration.IConfiguration configuration) { throw null; }
+ public static T? Get<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] T>(this Microsoft.Extensions.Configuration.IConfiguration configuration) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.")]
- public static T Get<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] T>(this Microsoft.Extensions.Configuration.IConfiguration configuration, System.Action configureOptions) { throw null; }
+ public static T? Get<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] T>(this Microsoft.Extensions.Configuration.IConfiguration configuration, System.Action? configureOptions) { throw null; }
}
}
diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/ref/Microsoft.Extensions.Configuration.Binder.csproj b/src/libraries/Microsoft.Extensions.Configuration.Binder/ref/Microsoft.Extensions.Configuration.Binder.csproj
index 154dc3b84a94f..fefa5f0049cae 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Binder/ref/Microsoft.Extensions.Configuration.Binder.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/ref/Microsoft.Extensions.Configuration.Binder.csproj
@@ -1,14 +1,26 @@
- netstandard2.0;$(NetFrameworkMinimum)
+ $(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)
+ enable
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs b/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs
index 2cbcfbb1c089e..993eb965c73d2 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs
+++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs
@@ -29,7 +29,7 @@ public static class ConfigurationBinder
/// The configuration instance to bind.
/// The new instance of T if successful, default(T) otherwise.
[RequiresUnreferencedCode(TrimmingWarningMessage)]
- public static T Get<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration)
+ public static T? Get<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration)
=> configuration.Get(_ => { });
///
@@ -42,14 +42,14 @@ public static class ConfigurationBinder
/// Configures the binder options.
/// The new instance of T if successful, default(T) otherwise.
[RequiresUnreferencedCode(TrimmingWarningMessage)]
- public static T Get<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration, Action configureOptions)
+ public static T? Get<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration, Action? configureOptions)
{
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}
- object result = configuration.Get(typeof(T), configureOptions);
+ object? result = configuration.Get(typeof(T), configureOptions);
if (result == null)
{
return default(T);
@@ -66,7 +66,7 @@ public static class ConfigurationBinder
/// The type of the new instance to bind.
/// The new instance if successful, null otherwise.
[RequiresUnreferencedCode(TrimmingWarningMessage)]
- public static object Get(this IConfiguration configuration, Type type)
+ public static object? Get(this IConfiguration configuration, Type type)
=> configuration.Get(type, _ => { });
///
@@ -79,11 +79,11 @@ public static object Get(this IConfiguration configuration, Type type)
/// Configures the binder options.
/// The new instance if successful, null otherwise.
[RequiresUnreferencedCode(TrimmingWarningMessage)]
- public static object Get(
+ public static object? Get(
this IConfiguration configuration,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Type type,
- Action configureOptions)
+ Action? configureOptions)
{
if (configuration == null)
{
@@ -102,7 +102,7 @@ public static object Get(
/// The key of the configuration section to bind.
/// The object to bind.
[RequiresUnreferencedCode(InstanceGetTypeTrimmingWarningMessage)]
- public static void Bind(this IConfiguration configuration, string key, object instance)
+ public static void Bind(this IConfiguration configuration, string key, object? instance)
=> configuration.GetSection(key).Bind(instance);
///
@@ -111,8 +111,8 @@ public static void Bind(this IConfiguration configuration, string key, object in
/// The configuration instance to bind.
/// The object to bind.
[RequiresUnreferencedCode(InstanceGetTypeTrimmingWarningMessage)]
- public static void Bind(this IConfiguration configuration, object instance)
- => configuration.Bind(instance, o => { });
+ public static void Bind(this IConfiguration configuration, object? instance)
+ => configuration.Bind(instance, _ => { });
///
/// Attempts to bind the given object instance to configuration values by matching property names against configuration keys recursively.
@@ -121,7 +121,7 @@ public static void Bind(this IConfiguration configuration, object instance)
/// The object to bind.
/// Configures the binder options.
[RequiresUnreferencedCode(InstanceGetTypeTrimmingWarningMessage)]
- public static void Bind(this IConfiguration configuration, object instance, Action configureOptions)
+ public static void Bind(this IConfiguration configuration, object? instance, Action? configureOptions)
{
if (configuration == null)
{
@@ -144,7 +144,7 @@ public static void Bind(this IConfiguration configuration, object instance, Acti
/// The key of the configuration section's value to convert.
/// The converted value.
[RequiresUnreferencedCode(TrimmingWarningMessage)]
- public static T GetValue<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration, string key)
+ public static T? GetValue<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration, string key)
{
return GetValue(configuration, key, default(T));
}
@@ -158,9 +158,9 @@ public static void Bind(this IConfiguration configuration, object instance, Acti
/// The default value to use if no value is found.
/// The converted value.
[RequiresUnreferencedCode(TrimmingWarningMessage)]
- public static T GetValue<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration, string key, T defaultValue)
+ public static T? GetValue<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration, string key, T defaultValue)
{
- return (T)GetValue(configuration, typeof(T), key, defaultValue);
+ return (T?)GetValue(configuration, typeof(T), key, defaultValue);
}
///
@@ -171,7 +171,7 @@ public static void Bind(this IConfiguration configuration, object instance, Acti
/// The key of the configuration section's value to convert.
/// The converted value.
[RequiresUnreferencedCode(TrimmingWarningMessage)]
- public static object GetValue(
+ public static object? GetValue(
this IConfiguration configuration,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Type type,
@@ -189,14 +189,14 @@ public static object GetValue(
/// The default value to use if no value is found.
/// The converted value.
[RequiresUnreferencedCode(TrimmingWarningMessage)]
- public static object GetValue(
+ public static object? GetValue(
this IConfiguration configuration,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Type type, string key,
- object defaultValue)
+ object? defaultValue)
{
IConfigurationSection section = configuration.GetSection(key);
- string value = section.Value;
+ string? value = section.Value;
if (value != null)
{
return ConvertValue(type, value, section.Path);
@@ -205,7 +205,7 @@ public static object GetValue(
}
[RequiresUnreferencedCode(PropertyTrimmingWarningMessage)]
- private static void BindNonScalar(this IConfiguration configuration, object instance, BinderOptions options)
+ private static void BindNonScalar(this IConfiguration configuration, object? instance, BinderOptions options)
{
if (instance != null)
{
@@ -256,7 +256,7 @@ private static void BindProperty(PropertyInfo property, object instance, IConfig
return;
}
- object propertyValue = GetPropertyValue(property, instance, config, options);
+ object? propertyValue = GetPropertyValue(property, instance, config, options);
if (propertyValue != null)
{
@@ -265,17 +265,17 @@ private static void BindProperty(PropertyInfo property, object instance, IConfig
}
[RequiresUnreferencedCode("Cannot statically analyze what the element type is of the object collection in type so its members may be trimmed.")]
- private static object BindToCollection(Type type, IConfiguration config, BinderOptions options)
+ private static object? BindToCollection(Type type, IConfiguration config, BinderOptions options)
{
Type genericType = typeof(List<>).MakeGenericType(type.GenericTypeArguments[0]);
- object instance = Activator.CreateInstance(genericType);
+ object? instance = Activator.CreateInstance(genericType);
BindCollection(instance, genericType, config, options);
return instance;
}
// Try to create an array/dictionary instance to back various collection interfaces
[RequiresUnreferencedCode("In case type is a Dictionary, cannot statically analyze what the element type is of the value objects in the dictionary so its members may be trimmed.")]
- private static object AttemptBindToCollectionInterfaces(
+ private static object? AttemptBindToCollectionInterfaces(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Type type,
IConfiguration config, BinderOptions options)
@@ -285,7 +285,7 @@ private static object AttemptBindToCollectionInterfaces(
return null;
}
- Type collectionInterface = FindOpenGenericInterface(typeof(IReadOnlyList<>), type);
+ Type? collectionInterface = FindOpenGenericInterface(typeof(IReadOnlyList<>), type);
if (collectionInterface != null)
{
// IEnumerable is guaranteed to have exactly one parameter
@@ -296,7 +296,7 @@ private static object AttemptBindToCollectionInterfaces(
if (collectionInterface != null)
{
Type dictionaryType = typeof(Dictionary<,>).MakeGenericType(type.GenericTypeArguments[0], type.GenericTypeArguments[1]);
- object instance = Activator.CreateInstance(dictionaryType);
+ object? instance = Activator.CreateInstance(dictionaryType);
BindDictionary(instance, dictionaryType, config, options);
return instance;
}
@@ -304,7 +304,7 @@ private static object AttemptBindToCollectionInterfaces(
collectionInterface = FindOpenGenericInterface(typeof(IDictionary<,>), type);
if (collectionInterface != null)
{
- object instance = Activator.CreateInstance(typeof(Dictionary<,>).MakeGenericType(type.GenericTypeArguments[0], type.GenericTypeArguments[1]));
+ object? instance = Activator.CreateInstance(typeof(Dictionary<,>).MakeGenericType(type.GenericTypeArguments[0], type.GenericTypeArguments[1]));
BindDictionary(instance, collectionInterface, config, options);
return instance;
}
@@ -334,10 +334,10 @@ private static object AttemptBindToCollectionInterfaces(
}
[RequiresUnreferencedCode(TrimmingWarningMessage)]
- private static object BindInstance(
+ private static object? BindInstance(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Type type,
- object instance, IConfiguration config, BinderOptions options)
+ object? instance, IConfiguration config, BinderOptions options)
{
// if binding IConfigurationSection, break early
if (type == typeof(IConfigurationSection))
@@ -346,10 +346,8 @@ private static object BindInstance(
}
var section = config as IConfigurationSection;
- string configValue = section?.Value;
- object convertedValue;
- Exception error;
- if (configValue != null && TryConvertValue(type, configValue, section.Path, out convertedValue, out error))
+ string? configValue = section?.Value;
+ if (configValue != null && TryConvertValue(type, configValue, section?.Path, out object? convertedValue, out Exception? error))
{
if (error != null)
{
@@ -376,14 +374,14 @@ private static object BindInstance(
}
// See if its a Dictionary
- Type collectionInterface = FindOpenGenericInterface(typeof(IDictionary<,>), type);
+ Type? collectionInterface = FindOpenGenericInterface(typeof(IDictionary<,>), type);
if (collectionInterface != null)
{
BindDictionary(instance, collectionInterface, config, options);
}
else if (type.IsArray)
{
- instance = BindArray((Array)instance, config, options);
+ instance = BindArray((Array)instance!, config, options);
}
else
{
@@ -404,7 +402,7 @@ private static object BindInstance(
return instance;
}
- private static object CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type)
+ private static object? CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type)
{
if (type.IsInterface || type.IsAbstract)
{
@@ -418,7 +416,7 @@ private static object CreateInstance([DynamicallyAccessedMembers(DynamicallyAcce
throw new InvalidOperationException(SR.Format(SR.Error_UnsupportedMultidimensionalArray, type));
}
- return Array.CreateInstance(type.GetElementType(), 0);
+ return Array.CreateInstance(type.GetElementType()!, 0);
}
if (!type.IsValueType)
@@ -442,7 +440,7 @@ private static object CreateInstance([DynamicallyAccessedMembers(DynamicallyAcce
[RequiresUnreferencedCode("Cannot statically analyze what the element type is of the value objects in the dictionary so its members may be trimmed.")]
private static void BindDictionary(
- object dictionary,
+ object? dictionary,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)]
Type dictionaryType,
IConfiguration config, BinderOptions options)
@@ -458,10 +456,10 @@ private static void BindDictionary(
return;
}
- PropertyInfo setter = dictionaryType.GetProperty("Item", DeclaredOnlyLookup);
+ PropertyInfo setter = dictionaryType.GetProperty("Item", DeclaredOnlyLookup)!;
foreach (IConfigurationSection child in config.GetChildren())
{
- object item = BindInstance(
+ object? item = BindInstance(
type: valueType,
instance: null,
config: child,
@@ -484,27 +482,27 @@ private static void BindDictionary(
[RequiresUnreferencedCode("Cannot statically analyze what the element type is of the object collection so its members may be trimmed.")]
private static void BindCollection(
- object collection,
+ object? collection,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)]
Type collectionType,
IConfiguration config, BinderOptions options)
{
// ICollection is guaranteed to have exactly one parameter
Type itemType = collectionType.GenericTypeArguments[0];
- MethodInfo addMethod = collectionType.GetMethod("Add", DeclaredOnlyLookup);
+ MethodInfo? addMethod = collectionType.GetMethod("Add", DeclaredOnlyLookup);
foreach (IConfigurationSection section in config.GetChildren())
{
try
{
- object item = BindInstance(
+ object? item = BindInstance(
type: itemType,
instance: null,
config: section,
options: options);
if (item != null)
{
- addMethod.Invoke(collection, new[] { item });
+ addMethod?.Invoke(collection, new[] { item });
}
}
catch
@@ -518,7 +516,7 @@ private static Array BindArray(Array source, IConfiguration config, BinderOption
{
IConfigurationSection[] children = config.GetChildren().ToArray();
int arrayLength = source.Length;
- Type elementType = source.GetType().GetElementType();
+ Type? elementType = source.GetType().GetElementType()!;
var newArray = Array.CreateInstance(elementType, arrayLength + children.Length);
// binding to array has to preserve already initialized arrays with values
@@ -531,7 +529,7 @@ private static Array BindArray(Array source, IConfiguration config, BinderOption
{
try
{
- object item = BindInstance(
+ object? item = BindInstance(
type: elementType,
instance: null,
config: children[i],
@@ -553,7 +551,7 @@ private static Array BindArray(Array source, IConfiguration config, BinderOption
private static bool TryConvertValue(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Type type,
- string value, string path, out object result, out Exception error)
+ string value, string? path, out object? result, out Exception? error)
{
error = null;
result = null;
@@ -569,7 +567,7 @@ private static bool TryConvertValue(
{
return true;
}
- return TryConvertValue(Nullable.GetUnderlyingType(type), value, path, out result, out error);
+ return TryConvertValue(Nullable.GetUnderlyingType(type)!, value, path, out result, out error);
}
TypeConverter converter = TypeDescriptor.GetConverter(type);
@@ -603,14 +601,12 @@ private static bool TryConvertValue(
}
[RequiresUnreferencedCode(TrimmingWarningMessage)]
- private static object ConvertValue(
+ private static object? ConvertValue(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Type type,
- string value, string path)
+ string value, string? path)
{
- object result;
- Exception error;
- TryConvertValue(type, value, path, out result, out error);
+ TryConvertValue(type, value, path, out object? result, out Exception? error);
if (error != null)
{
throw error;
@@ -618,7 +614,7 @@ private static object ConvertValue(
return result;
}
- private static Type FindOpenGenericInterface(
+ private static Type? FindOpenGenericInterface(
Type expected,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
Type actual)
@@ -647,18 +643,19 @@ private static List GetAllProperties(
{
var allProperties = new List();
+ Type? baseType = type;
do
{
- allProperties.AddRange(type.GetProperties(DeclaredOnlyLookup));
- type = type.BaseType;
+ allProperties.AddRange(baseType!.GetProperties(DeclaredOnlyLookup));
+ baseType = baseType.BaseType;
}
- while (type != typeof(object));
+ while (baseType != typeof(object));
return allProperties;
}
[RequiresUnreferencedCode(PropertyTrimmingWarningMessage)]
- private static object GetPropertyValue(PropertyInfo property, object instance, IConfiguration config, BinderOptions options)
+ private static object? GetPropertyValue(PropertyInfo property, object instance, IConfiguration config, BinderOptions options)
{
string propertyName = GetPropertyName(property);
return BindInstance(
@@ -690,7 +687,7 @@ private static string GetPropertyName(MemberInfo property)
}
// Assumes ConfigurationKeyName constructor first arg is the string key name
- string name = attributeData
+ string? name = attributeData
.ConstructorArguments[0]
.Value?
.ToString();
diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/src/Microsoft.Extensions.Configuration.Binder.csproj b/src/libraries/Microsoft.Extensions.Configuration.Binder/src/Microsoft.Extensions.Configuration.Binder.csproj
index 6f384e43a071b..a04a112aee18a 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Binder/src/Microsoft.Extensions.Configuration.Binder.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/src/Microsoft.Extensions.Configuration.Binder.csproj
@@ -1,13 +1,19 @@
- netstandard2.0;$(NetFrameworkMinimum)
+ $(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)
+ enable
true
+
+ false
Functionality to bind an object to data in configuration providers for Microsoft.Extensions.Configuration.
+
+
+