1using System.Diagnostics.CodeAnalysis;
2using System.Reflection;
14 Type type = value.GetType();
15 Type nullableUnderlyingType = Nullable.GetUnderlyingType(type);
17 return nullableUnderlyingType ==
null
21 catch (Exception innerException) {
22 throw new InvalidOperationException($
"Cannot convert value of type \"{type.FullName}\" to string.", innerException);
28 Type nullableUnderlyingType = Nullable.GetUnderlyingType(type);
29 if (nullableUnderlyingType ==
null) {
33 if (
string.IsNullOrEmpty(data)) {
57 Type nullableUnderlyingType = Nullable.GetUnderlyingType(type);
61 catch (Exception innerException) {
62 throw new InvalidOperationException($
"Cannot convert string \"{data}\" to value of type \"{type.FullName}\".", innerException);
71 string[] array =
new string[values.Length];
72 for (
int i = 0; i < values.Length; i++) {
75 return string.Join(separator.ToString(), array);
79 if (!
string.IsNullOrEmpty(data)) {
81 string[] array = data.Split([separator], StringSplitOptions.None);
83 string[] array = data.Split(separator);
85 T[] array2 =
new T[array.Length];
86 for (
int i = 0; i < array.Length; i++) {
95 ArgumentNullException.ThrowIfNull(type);
101 if (type.GetTypeInfo().IsSubclassOf(item.Key)) {
111 ?
throw new InvalidOperationException(
112 $
"IHumanReadableConverter for type \"{type.FullName}\" not found in any loaded assembly."
121#pragma warning disable IL2026
122 foreach (TypeInfo definedType
in item.DefinedTypes) {
123#pragma warning restore IL2026
125 if (customAttribute !=
null) {
126 Type[] types = customAttribute.
Types;
127 foreach (Type key
in types) {
129#pragma warning disable IL2072
131#pragma warning restore IL2072
static string ConvertToString(object value)
static void ScanAssembliesForConverters()
static bool TryConvertFromString< T >(string data, out T result)
static string ValuesListToString< T >(char separator, params T[] values)
static HashSet< Assembly > m_scannedAssemblies
static Dictionary< Type, IHumanReadableConverter > m_humanReadableConvertersByType
static bool IsTypeSupported(Type type)
static bool TryConvertFromString(Type type, string data, out object result)
static T[] ValuesListFromString< T >(char separator, string data)
static IHumanReadableConverter GetConverter(Type type, bool throwIfNotFound)
static object ConvertFromString(Type type, string data)
static T ConvertFromString< T >(string data)
static bool IsKnownSystemAssembly(Assembly assembly)
static ReadOnlyList< Assembly > LoadedAssemblies
object ConvertFromString(Type type, string data)
string ConvertToString(object value)