forked from ClearFoundry/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptObject.cs
More file actions
129 lines (114 loc) · 5.22 KB
/
Copy pathScriptObject.cs
File metadata and controls
129 lines (114 loc) · 5.22 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
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using Microsoft.ClearScript.Util;
namespace Microsoft.ClearScript
{
/// <summary>
/// Represents a script object.
/// </summary>
/// <c><seealso cref="ScriptEngine.Evaluate(string, bool, string)"/></c>
public abstract class ScriptObject : DynamicObject
{
internal ScriptObject()
{
}
/// <summary>
/// Gets the script engine that owns the object.
/// </summary>
public abstract ScriptEngine Engine { get; }
/// <summary>
/// Gets the value of a named script object property.
/// </summary>
/// <param name="name">The name of the property to get.</param>
/// <param name="args">Optional arguments for property retrieval.</param>
/// <returns>The value of the specified property.</returns>
public abstract object GetProperty(string name, params object[] args);
/// <summary>
/// Sets the value of a named script object property.
/// </summary>
/// <param name="name">The name of the property to set.</param>
/// <param name="args">An array containing optional arguments and the new property value.</param>
/// <remarks>
/// The <paramref name="args"></paramref> array must contain at least one element. The new
/// property value must be the last element of the array.
/// </remarks>
public abstract void SetProperty(string name, params object[] args);
/// <summary>
/// Removes a named script object property.
/// </summary>
/// <param name="name">The name of the property to remove.</param>
/// <returns><c>True</c> if the property was removed successfully, <c>false</c> otherwise.</returns>
public abstract bool DeleteProperty(string name);
/// <summary>
/// Enumerates the script object's property names.
/// </summary>
public abstract IEnumerable<string> PropertyNames { get; }
/// <summary>
/// Gets or sets the value of a named script object property.
/// </summary>
/// <param name="name">The name of the property to get or set.</param>
/// <param name="args">Optional arguments for property access.</param>
/// <returns>The value of the specified property.</returns>
public object this[string name, params object[] args]
{
get => GetProperty(name, args);
set => SetProperty(name, args.Concat(value.ToEnumerable()).ToArray());
}
/// <summary>
/// Gets the value of an indexed script object property.
/// </summary>
/// <param name="index">The index of the property to get.</param>
/// <returns>The value of the specified property.</returns>
public abstract object GetProperty(int index);
/// <summary>
/// Sets the value of an indexed script object property.
/// </summary>
/// <param name="index">The index of the property to set.</param>
/// <param name="value">The new property value.</param>
public abstract void SetProperty(int index, object value);
/// <summary>
/// Removes an indexed script object property.
/// </summary>
/// <param name="index">The index of the property to remove.</param>
/// <returns><c>True</c> if the property was removed successfully, <c>false</c> otherwise.</returns>
public abstract bool DeleteProperty(int index);
/// <summary>
/// Enumerates the script object's property indices.
/// </summary>
public abstract IEnumerable<int> PropertyIndices { get; }
/// <summary>
/// Gets or sets the value of an indexed script object property.
/// </summary>
/// <param name="index">The index of the property to get or set.</param>
/// <returns>The value of the specified property.</returns>
public object this[int index]
{
get => GetProperty(index);
set => SetProperty(index, value);
}
/// <summary>
/// Invokes the script object.
/// </summary>
/// <param name="asConstructor"><c>True</c> to invoke the object as a constructor, <c>false</c> otherwise.</param>
/// <param name="args">Optional arguments for object invocation.</param>
/// <returns>The invocation result value.</returns>
public abstract object Invoke(bool asConstructor, params object[] args);
/// <summary>
/// Invokes a script object method.
/// </summary>
/// <param name="name">The name of the method to invoke.</param>
/// <param name="args">Optional arguments for method invocation.</param>
/// <returns>The invocation result value.</returns>
public abstract object InvokeMethod(string name, params object[] args);
/// <summary>
/// Invokes the script object as a function.
/// </summary>
/// <param name="args">Optional arguments for object invocation.</param>
/// <returns>The invocation result value.</returns>
public object InvokeAsFunction(params object[] args)
{
return Invoke(false, args);
}
}
}