Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ReflectorNet/src/Convertor/Json/EnumJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))}");
}
Expand Down
2 changes: 1 addition & 1 deletion ReflectorNet/src/Reflector/MethodWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public virtual bool VerifyParameters(IReadOnlyDictionary<string, object?>? named
{
if (Enum.TryParse(parameterType, stringValue, ignoreCase: true, out var result))
{
if (Enum.IsDefined(parameterType, result))
if (Enum.IsDefined(parameterType, result!))
{
return result;
}
Expand Down
11 changes: 6 additions & 5 deletions ReflectorNet/src/Utils/MethodUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ namespace com.IvanMurzak.ReflectorNet.Utils
/// </summary>
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

/// <summary>
/// Determines whether the return type of a method is nullable.
Expand Down Expand Up @@ -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
Comment thread
IvanMurzak marked this conversation as resolved.
// 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;
Expand Down
5 changes: 3 additions & 2 deletions ReflectorNet/src/Utils/TypeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Comment thread
IvanMurzak marked this conversation as resolved.
public static string? GetPropertyDescription(System.Text.Json.Schema.JsonSchemaExporterContext context)
{
if (context.PropertyInfo == null || context.PropertyInfo.DeclaringType == null)
return null;
Expand Down Expand Up @@ -169,6 +169,7 @@ public static bool IsDictionary(Type type)

return GetDescription(memberInfo);
}
#endif

private static string ToPascalCase(string camelCase)
{
Expand Down
Loading