Skip to content

Commit

Permalink
Renamed variable to clarify code.
Browse files Browse the repository at this point in the history
  • Loading branch information
nkosi23 committed Dec 11, 2024
1 parent 9469e30 commit 5fba70a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Marten/Util/GenericsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static object UnwrapIEnumerableOfNullables(this object obj)
i.GetGenericArguments()[0].GetGenericTypeDefinition() == typeof(Nullable<>)))
{
// Get the underlying type of the Nullable<T>
var underlyingType = type.GetInterfaces()
var strongIdtype = type.GetInterfaces()
.First(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEnumerable<>))
.GetGenericArguments()[0]
.GetGenericArguments()[0];
Expand All @@ -35,10 +35,10 @@ public static object UnwrapIEnumerableOfNullables(this object obj)
.Select(x => x.GetType().GetProperty("Value").GetValue(x));

// Create an array of the underlying type
obj = Array.CreateInstance(underlyingType, unwrappedValues.Count());
obj = Array.CreateInstance(strongIdtype, unwrappedValues.Count());
var stronglyTypedValues = unwrappedValues.Select(x =>
{
var constructor = underlyingType.GetConstructor(new[] { x.GetType() });
var constructor = strongIdtype.GetConstructor(new[] { x.GetType() });
object strongTypedId;
if (constructor != null)
{
Expand All @@ -47,15 +47,15 @@ public static object UnwrapIEnumerableOfNullables(this object obj)
else
{
// Use static builder method if no constructor is found. User can name the builder method anyway they want.
var fromMethod = underlyingType.GetMethods(BindingFlags.Public | BindingFlags.Static)
var fromMethod = strongIdtype.GetMethods(BindingFlags.Public | BindingFlags.Static)
.FirstOrDefault(m =>
m.ReturnType == underlyingType &&
m.ReturnType == strongIdtype &&
m.GetParameters().Length == 1 &&
m.GetParameters()[0].ParameterType == x.GetType()
);
if (fromMethod == null)
{
throw new InvalidOperationException($"Type {underlyingType} does not have a constructor or a static 'From' method.");
throw new InvalidOperationException($"Type {strongIdtype} does not have a constructor or a static 'From' method.");
}
strongTypedId = fromMethod.Invoke(null, new[] { x });
}
Expand Down

0 comments on commit 5fba70a

Please sign in to comment.