Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DumboJetEngine committed Jan 8, 2024
1 parent 85451de commit 1e68d21
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/OpenSearch.Client/Mapping/Visitor/PropertyWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,27 @@ private static Type GetUnderlyingType(Type type)
if (type.IsArray)
return type.GetElementType();

if (type.IsGenericType && type.GetGenericArguments().Length == 1
&& (type.GetInterfaces().HasAny(t => t == typeof(IEnumerable)) || Nullable.GetUnderlyingType(type) != null))
return type.GetGenericArguments()[0];
if (ShouldUnwrapType(type))
{
var returnType = type.GetGenericArguments()[0];
if (ShouldUnwrapType(returnType)) // This is needed for types like IEnumerable<int?>.
{
return returnType.GetGenericArguments()[0];
}
return returnType;
}

return type;

bool ShouldUnwrapType(Type ty)
{
return ty.IsGenericType &&
ty.GetGenericArguments().Length == 1
&& (
ty.GetInterfaces().HasAny(t => t == typeof(IEnumerable)) ||
Nullable.GetUnderlyingType(ty) != null
);
}
}
}
}

0 comments on commit 1e68d21

Please sign in to comment.