forked from Taritsyn/MsieJavaScriptEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHostType.cs
More file actions
60 lines (49 loc) · 1.65 KB
/
HostType.cs
File metadata and controls
60 lines (49 loc) · 1.65 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
#if !NETSTANDARD
using System;
using System.Globalization;
using System.Linq;
using System.Reflection;
using MsieJavaScriptEngine.Constants;
using MsieJavaScriptEngine.Helpers;
namespace MsieJavaScriptEngine
{
/// <summary>
/// Wrapper for type, that implements <see cref="IReflect"/> interface
/// </summary>
internal sealed class HostType : HostItemBase
{
/// <summary>
/// Constructs an instance of the wrapper for type, that implements <see cref="IReflect"/> interface
/// </summary>
/// <param name="type">Target type</param>
/// <param name="engineMode">JS engine mode</param>
public HostType(Type type, JsEngineMode engineMode)
: base(type, null, engineMode, false)
{ }
#region HostItemBase overrides
protected override object InnerInvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target,
object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)
{
object result;
if (name == SpecialMemberName.Default && invokeAttr.HasFlag(BindingFlags.CreateInstance))
{
object[] processedArgs = args;
if (_engineMode != JsEngineMode.Classic && processedArgs.Length > 0)
{
processedArgs = processedArgs.Skip(1).ToArray();
}
processedArgs = TypeMappingHelpers.MapToHostType(processedArgs);
result = Activator.CreateInstance(_type, processedArgs);
}
else
{
object[] processedArgs = TypeMappingHelpers.MapToHostType(args);
result = InvokeStandardMember(name, invokeAttr, binder, target,
processedArgs, modifiers, culture, namedParameters);
}
return TypeMappingHelpers.MapToScriptType(result, _engineMode);
}
#endregion
}
}
#endif