|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | + |
| 7 | +namespace Microsoft.ClearScript |
| 8 | +{ |
| 9 | + /// <summary> |
| 10 | + /// Represents a script object. |
| 11 | + /// </summary> |
| 12 | + public interface IScriptObject : IDisposable |
| 13 | + { |
| 14 | + /// <summary> |
| 15 | + /// Gets the script engine that owns the object. |
| 16 | + /// </summary> |
| 17 | + ScriptEngine Engine { get; } |
| 18 | + |
| 19 | + /// <summary> |
| 20 | + /// Gets the value of a named script object property. |
| 21 | + /// </summary> |
| 22 | + /// <param name="name">The name of the property to get.</param> |
| 23 | + /// <param name="args">Optional arguments for property retrieval.</param> |
| 24 | + /// <returns>The value of the specified property.</returns> |
| 25 | + object GetProperty(string name, params object[] args); |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Sets the value of a named script object property. |
| 29 | + /// </summary> |
| 30 | + /// <param name="name">The name of the property to set.</param> |
| 31 | + /// <param name="args">An array containing optional arguments and the new property value.</param> |
| 32 | + /// <remarks> |
| 33 | + /// The <paramref name="args"></paramref> array must contain at least one element. The new |
| 34 | + /// property value must be the last element of the array. |
| 35 | + /// </remarks> |
| 36 | + void SetProperty(string name, params object[] args); |
| 37 | + |
| 38 | + /// <summary> |
| 39 | + /// Removes a named script object property. |
| 40 | + /// </summary> |
| 41 | + /// <param name="name">The name of the property to remove.</param> |
| 42 | + /// <returns><c>True</c> if the property was removed successfully, <c>false</c> otherwise.</returns> |
| 43 | + bool DeleteProperty(string name); |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// Enumerates the script object's property names. |
| 47 | + /// </summary> |
| 48 | + IEnumerable<string> PropertyNames { get; } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Gets or sets the value of a named script object property. |
| 52 | + /// </summary> |
| 53 | + /// <param name="name">The name of the property to get or set.</param> |
| 54 | + /// <param name="args">Optional arguments for property access.</param> |
| 55 | + /// <returns>The value of the specified property.</returns> |
| 56 | + object this[string name, params object[] args] { get; set; } |
| 57 | + |
| 58 | + /// <summary> |
| 59 | + /// Gets the value of an indexed script object property. |
| 60 | + /// </summary> |
| 61 | + /// <param name="index">The index of the property to get.</param> |
| 62 | + /// <returns>The value of the specified property.</returns> |
| 63 | + object GetProperty(int index); |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Sets the value of an indexed script object property. |
| 67 | + /// </summary> |
| 68 | + /// <param name="index">The index of the property to set.</param> |
| 69 | + /// <param name="value">The new property value.</param> |
| 70 | + void SetProperty(int index, object value); |
| 71 | + |
| 72 | + /// <summary> |
| 73 | + /// Removes an indexed script object property. |
| 74 | + /// </summary> |
| 75 | + /// <param name="index">The index of the property to remove.</param> |
| 76 | + /// <returns><c>True</c> if the property was removed successfully, <c>false</c> otherwise.</returns> |
| 77 | + bool DeleteProperty(int index); |
| 78 | + |
| 79 | + /// <summary> |
| 80 | + /// Enumerates the script object's property indices. |
| 81 | + /// </summary> |
| 82 | + IEnumerable<int> PropertyIndices { get; } |
| 83 | + |
| 84 | + /// <summary> |
| 85 | + /// Gets or sets the value of an indexed script object property. |
| 86 | + /// </summary> |
| 87 | + /// <param name="index">The index of the property to get or set.</param> |
| 88 | + /// <returns>The value of the specified property.</returns> |
| 89 | + object this[int index] { get; set; } |
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// Invokes the script object. |
| 93 | + /// </summary> |
| 94 | + /// <param name="asConstructor"><c>True</c> to invoke the object as a constructor, <c>false</c> otherwise.</param> |
| 95 | + /// <param name="args">Optional arguments for object invocation.</param> |
| 96 | + /// <returns>The invocation result value.</returns> |
| 97 | + object Invoke(bool asConstructor, params object[] args); |
| 98 | + |
| 99 | + /// <summary> |
| 100 | + /// Invokes a script object method. |
| 101 | + /// </summary> |
| 102 | + /// <param name="name">The name of the method to invoke.</param> |
| 103 | + /// <param name="args">Optional arguments for method invocation.</param> |
| 104 | + /// <returns>The invocation result value.</returns> |
| 105 | + object InvokeMethod(string name, params object[] args); |
| 106 | + |
| 107 | + /// <summary> |
| 108 | + /// Invokes the script object as a function. |
| 109 | + /// </summary> |
| 110 | + /// <param name="args">Optional arguments for object invocation.</param> |
| 111 | + /// <returns>The invocation result value.</returns> |
| 112 | + object InvokeAsFunction(params object[] args); |
| 113 | + } |
| 114 | +} |
0 commit comments