TODO: Extend converting from types
(object? value)
| 51 | |
| 52 | // TODO: Extend converting from types |
| 53 | public static LocalValue ConvertFrom(object? value) |
| 54 | { |
| 55 | switch (value) |
| 56 | { |
| 57 | case LocalValue localValue: |
| 58 | return localValue; |
| 59 | |
| 60 | case null: |
| 61 | return new NullLocalValue(); |
| 62 | |
| 63 | case bool b: |
| 64 | return ConvertFrom(b); |
| 65 | |
| 66 | case int i: |
| 67 | return ConvertFrom(i); |
| 68 | |
| 69 | case double d: |
| 70 | return ConvertFrom(d); |
| 71 | |
| 72 | case long l: |
| 73 | return ConvertFrom(l); |
| 74 | |
| 75 | case DateTimeOffset dt: |
| 76 | return ConvertFrom(dt); |
| 77 | |
| 78 | case BigInteger bigInt: |
| 79 | return ConvertFrom(bigInt); |
| 80 | |
| 81 | case string str: |
| 82 | return ConvertFrom(str); |
| 83 | |
| 84 | case Regex regex: |
| 85 | return ConvertFrom(regex); |
| 86 | |
| 87 | case { } when value.GetType().GetInterfaces() |
| 88 | .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ISet<>)): |
| 89 | { |
| 90 | IEnumerable set = (IEnumerable)value; |
| 91 | |
| 92 | return new SetLocalValue([.. set.Cast<object?>().Select(ConvertFrom)]); |
| 93 | } |
| 94 | |
| 95 | case IDictionary dictionary: |
| 96 | return ConvertFrom(dictionary); |
| 97 | |
| 98 | case IEnumerable enumerable: |
| 99 | return ConvertFrom(enumerable); |
| 100 | |
| 101 | default: |
| 102 | return ReflectionBasedConvertFrom(value); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | public static LocalValue ConvertFrom(bool? value) |
| 107 | { |