diff --git a/ReflectorNet/src/Convertor/Json/EnumJsonConverter.cs b/ReflectorNet/src/Convertor/Json/EnumJsonConverter.cs index a85c272..c23daf2 100644 --- a/ReflectorNet/src/Convertor/Json/EnumJsonConverter.cs +++ b/ReflectorNet/src/Convertor/Json/EnumJsonConverter.cs @@ -63,8 +63,8 @@ public override bool CanConvert(Type typeToConvert) if (!Enum.TryParse(underlyingType, stringValue, ignoreCase: true, out var enumValue)) throw new JsonException($"Unable to convert '{stringValue}' to enum {underlyingType.Name}. Valid values are: {string.Join(", ", Enum.GetNames(underlyingType))}"); - if (Enum.IsDefined(underlyingType, enumValue)) - return enumValue; + if (Enum.IsDefined(underlyingType, enumValue!)) + return enumValue!; throw new JsonException($"Unable to convert '{stringValue}' to enum {underlyingType.Name}. Valid values are: {string.Join(", ", Enum.GetNames(underlyingType))}"); } diff --git a/ReflectorNet/src/Reflector/MethodWrapper.cs b/ReflectorNet/src/Reflector/MethodWrapper.cs index e1400ef..5ad7f8a 100644 --- a/ReflectorNet/src/Reflector/MethodWrapper.cs +++ b/ReflectorNet/src/Reflector/MethodWrapper.cs @@ -416,7 +416,7 @@ public virtual bool VerifyParameters(IReadOnlyDictionary? named { if (Enum.TryParse(parameterType, stringValue, ignoreCase: true, out var result)) { - if (Enum.IsDefined(parameterType, result)) + if (Enum.IsDefined(parameterType, result!)) { return result; } diff --git a/ReflectorNet/src/Utils/MethodUtils.cs b/ReflectorNet/src/Utils/MethodUtils.cs index acb74dc..f0455e6 100644 --- a/ReflectorNet/src/Utils/MethodUtils.cs +++ b/ReflectorNet/src/Utils/MethodUtils.cs @@ -16,17 +16,18 @@ namespace com.IvanMurzak.ReflectorNet.Utils /// public static class MethodUtils { -#if NET5_0_OR_GREATER // Cache the NullableContextAttribute type for performance // This is a compiler-generated internal attribute, so we must access it by name - private static readonly Type? NullableContextAttributeType = typeof(System.Runtime.CompilerServices.NullableContextAttribute); - // Type.GetType("System.Runtime.CompilerServices.NullableContextAttribute, System.Private.CoreLib"); +#if NET8_0_OR_GREATER + private static readonly Type NullableContextAttributeType = typeof(System.Runtime.CompilerServices.NullableContextAttribute); +#elif NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER // Maybe some environment would support it + private static readonly Type? NullableContextAttributeType = Type.GetType("System.Runtime.CompilerServices.NullableContextAttribute, System.Private.CoreLib"); +#endif // NullableContext attribute values private const byte NullableContextOblivious = 0; // No annotation - treat as non-nullable private const byte NullableContextNotNull = 1; // Non-nullable private const byte NullableContextNullable = 2; // Nullable -#endif /// /// Determines whether the return type of a method is nullable. @@ -77,7 +78,7 @@ public static bool IsReturnTypeNullable(MethodInfo methodInfo) ? returnType.GetGenericArguments()[0] : returnType; -#if NET5_0_OR_GREATER +#if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER // First, check if this is a method on a generic type - we need to inspect the generic definition // to correctly determine nullability for generic type parameters (T vs T?) MethodInfo? methodToInspect = null; diff --git a/ReflectorNet/src/Utils/TypeUtils.cs b/ReflectorNet/src/Utils/TypeUtils.cs index 7cd07e3..936f721 100644 --- a/ReflectorNet/src/Utils/TypeUtils.cs +++ b/ReflectorNet/src/Utils/TypeUtils.cs @@ -10,7 +10,6 @@ using System.ComponentModel; using System.Linq; using System.Reflection; -using System.Text.Json.Schema; using com.IvanMurzak.ReflectorNet.Model; namespace com.IvanMurzak.ReflectorNet.Utils @@ -132,7 +131,8 @@ public static bool IsDictionary(Type type) var propertyInfo = type.GetProperty(propertyName); return propertyInfo != null ? GetPropertyDescription(propertyInfo) : null; } - public static string? GetPropertyDescription(JsonSchemaExporterContext context) +#if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER + public static string? GetPropertyDescription(System.Text.Json.Schema.JsonSchemaExporterContext context) { if (context.PropertyInfo == null || context.PropertyInfo.DeclaringType == null) return null; @@ -169,6 +169,7 @@ public static bool IsDictionary(Type type) return GetDescription(memberInfo); } +#endif private static string ToPascalCase(string camelCase) {