-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathScriptMethod.cs
More file actions
130 lines (99 loc) · 4.03 KB
/
ScriptMethod.cs
File metadata and controls
130 lines (99 loc) · 4.03 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Globalization;
using System.Reflection;
using Microsoft.ClearScript.Util;
namespace Microsoft.ClearScript
{
internal sealed class ScriptMethod : HostTarget, IReflect
{
private readonly ScriptItem target;
private readonly string name;
public ScriptMethod(ScriptItem target, string name)
{
this.target = target;
this.name = name;
}
public object Invoke(params object[] args)
{
return target.InvokeMethod(name, args);
}
#region Object overrides
public override string ToString()
{
return MiscHelpers.FormatInvariant("ScriptMethod:{0}", name);
}
#endregion
#region HostTarget overrides
public override Type Type => typeof(void);
public override object Target => this;
public override object InvokeTarget => null;
public override object DynamicInvokeTarget => null;
public override HostTargetFlags GetFlags(IHostContext context)
{
return HostTargetFlags.None;
}
public override bool TryInvoke(IHostContext context, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
{
result = target.InvokeMethod(name, args);
return true;
}
public override Invocability GetInvocability(IHostContext context, BindingFlags bindFlags, bool ignoreDynamic)
{
return Invocability.Delegate;
}
#endregion
#region IReflect implementation
MethodInfo IReflect.GetMethod(string methodName, BindingFlags bindFlags, Binder binder, Type[] types, ParameterModifier[] modifiers)
{
throw new NotImplementedException();
}
MethodInfo IReflect.GetMethod(string methodName, BindingFlags bindFlags)
{
throw new NotImplementedException();
}
MethodInfo[] IReflect.GetMethods(BindingFlags bindFlags)
{
throw new NotImplementedException();
}
FieldInfo IReflect.GetField(string fieldName, BindingFlags bindFlags)
{
throw new NotImplementedException();
}
FieldInfo[] IReflect.GetFields(BindingFlags bindFlags)
{
throw new NotImplementedException();
}
PropertyInfo IReflect.GetProperty(string propertyName, BindingFlags bindFlags)
{
throw new NotImplementedException();
}
PropertyInfo IReflect.GetProperty(string propertyName, BindingFlags bindFlags, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
{
throw new NotImplementedException();
}
PropertyInfo[] IReflect.GetProperties(BindingFlags bindFlags)
{
throw new NotImplementedException();
}
MemberInfo[] IReflect.GetMember(string memberName, BindingFlags bindFlags)
{
// This occurs during VB-based dynamic script item invocation. It was not observed
// before script items gained an IReflect/IExpando implementation that exposes
// script item properties as fields. Apparently VB's dynamic invocation support not
// only recognizes IReflect/IExpando but actually favors it over DynamicObject.
return typeof(ScriptMethod).GetMember(memberName.ToNonBlank("Invoke"), bindFlags);
}
MemberInfo[] IReflect.GetMembers(BindingFlags bindFlags)
{
throw new NotImplementedException();
}
object IReflect.InvokeMember(string memberName, BindingFlags invokeFlags, Binder binder, object invokeTarget, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)
{
throw new NotImplementedException();
}
Type IReflect.UnderlyingSystemType => throw new NotImplementedException();
#endregion
}
}