Skip to content

Commit 25afdf1

Browse files
authored
Merge pull request #77 from vanjoge/master
Fix bug with null parameter
2 parents 596a49b + 72e4600 commit 25afdf1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/JavaScriptEngineSwitcher.ChakraCore/Helpers/ReflectionHelpers.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public static void FixFieldValueType(ref object value, FieldInfo field)
5959

6060
public static void FixPropertyValueType(ref object value, PropertyInfo property)
6161
{
62+
if (value == null) return;
6263
Type valueType = value.GetType();
6364
Type propertyType = property.PropertyType;
6465

@@ -80,6 +81,7 @@ public static void FixArgumentTypes(ref object[] argValues, ParameterInfo[] para
8081
for (int argIndex = 0; argIndex < argCount; argIndex++)
8182
{
8283
object argValue = argValues[argIndex];
84+
if (argValue == null) continue;
8385
Type argType = argValue.GetType();
8486

8587
ParameterInfo parameter = parameters[argIndex];
@@ -122,7 +124,17 @@ public static MethodBase GetBestFitMethod(MethodBase[] methods, object[] argValu
122124
}
123125

124126
Type[] argTypes = argValues
125-
.Select(a => a.GetType())
127+
.Select(a =>
128+
{
129+
if (a == null)
130+
{
131+
return null;
132+
}
133+
else
134+
{
135+
return a.GetType();
136+
}
137+
})
126138
.ToArray()
127139
;
128140
var compatibleMethods = new List<MethodWithMetadata>();
@@ -222,4 +234,4 @@ public ushort CompatibilityScore
222234
}
223235
}
224236
}
225-
}
237+
}

0 commit comments

Comments
 (0)