|
3 | 3 |
|
4 | 4 | #pragma warning disable AV1008 // Class should not be static
|
5 | 5 |
|
6 |
| -namespace JsonApiDotNetCore.Resources.Internal; |
| 6 | +namespace JsonApiDotNetCore.Resources; |
7 | 7 |
|
| 8 | +/// <summary> |
| 9 | +/// Provides utilities regarding runtime types. |
| 10 | +/// </summary> |
8 | 11 | [PublicAPI]
|
9 | 12 | public static class RuntimeTypeConverter
|
10 | 13 | {
|
11 | 14 | private const string ParseQueryStringsUsingCurrentCultureSwitchName = "JsonApiDotNetCore.ParseQueryStringsUsingCurrentCulture";
|
12 | 15 |
|
| 16 | + /// <summary> |
| 17 | + /// Converts the specified value to the specified type. |
| 18 | + /// </summary> |
| 19 | + /// <param name="value"> |
| 20 | + /// The value to convert from. |
| 21 | + /// </param> |
| 22 | + /// <param name="type"> |
| 23 | + /// The type to convert to. |
| 24 | + /// </param> |
| 25 | + /// <returns> |
| 26 | + /// The converted type, or <c>null</c> if <paramref name="value" /> is <c>null</c> and <paramref name="type" /> is a nullable type. |
| 27 | + /// </returns> |
| 28 | + /// <exception cref="FormatException"> |
| 29 | + /// <paramref name="value" /> is not compatible with <paramref name="type" />. |
| 30 | + /// </exception> |
13 | 31 | public static object? ConvertType(object? value, Type type)
|
14 | 32 | {
|
15 | 33 | ArgumentGuard.NotNull(type);
|
@@ -114,11 +132,20 @@ public static class RuntimeTypeConverter
|
114 | 132 | }
|
115 | 133 | }
|
116 | 134 |
|
| 135 | + /// <summary> |
| 136 | + /// Indicates whether the specified type is a nullable value type or a reference type. |
| 137 | + /// </summary> |
117 | 138 | public static bool CanContainNull(Type type)
|
118 | 139 | {
|
119 | 140 | return !type.IsValueType || Nullable.GetUnderlyingType(type) != null;
|
120 | 141 | }
|
121 | 142 |
|
| 143 | + /// <summary> |
| 144 | + /// Gets the default value for the specified type. |
| 145 | + /// </summary> |
| 146 | + /// <returns> |
| 147 | + /// The default value, or <c>null</c> for nullable value types and reference types. |
| 148 | + /// </returns> |
122 | 149 | public static object? GetDefaultValue(Type type)
|
123 | 150 | {
|
124 | 151 | return type.IsValueType ? Activator.CreateInstance(type) : null;
|
|
0 commit comments