-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathReflectionHelpers.cs
More file actions
48 lines (40 loc) · 1022 Bytes
/
ReflectionHelpers.cs
File metadata and controls
48 lines (40 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Reflection;
using JavaScriptEngineSwitcher.Core.Utilities;
namespace JavaScriptEngineSwitcher.Yantra.Helpers
{
/// <summary>
/// Reflection helpers
/// </summary>
internal static class ReflectionHelpers
{
public static void FixArgumentTypes(ref object[] argValues, ParameterInfo[] parameters)
{
int argCount = argValues.Length;
int parameterCount = parameters.Length;
for (int argIndex = 0; argIndex < argCount; argIndex++)
{
if (argIndex >= parameterCount)
{
break;
}
object argValue = argValues[argIndex];
if (argValue is null)
{
continue;
}
Type argType = argValue.GetType();
ParameterInfo parameter = parameters[argIndex];
Type parameterType = parameter.ParameterType;
if (argType != parameterType)
{
object convertedArgValue;
if (TypeConverter.TryConvertToType(argValue, parameterType, out convertedArgValue))
{
argValues[argIndex] = convertedArgValue;
}
}
}
}
}
}