/// <summary> /// Converts an object to a host object with the specified type restriction, for use with /// script code running in the specified script engine. /// </summary> /// <typeparam name="T">The type whose members are to be made accessible from script code.</typeparam> /// <param name="target">The object to convert to a host object for use with script code.</param> /// <param name="engine">The script engine in which the host object will be used.</param> /// <returns>A host object with the specified type restriction.</returns> public static object ToRestrictedHostObject <T>(this T target, ScriptEngine engine) { MiscHelpers.VerifyNonNullArgument(target, nameof(target)); MiscHelpers.VerifyNonNullArgument(engine, nameof(engine)); return(HostItem.Wrap(engine, target, typeof(T))); }
/// <summary> /// Exposes a host object to script code with the specified type restriction and options. /// </summary> /// <typeparam name="T">The type whose members are to be made accessible from script code.</typeparam> /// <param name="itemName">A name for the new global script item that will represent the object.</param> /// <param name="flags">A value that selects options for the operation.</param> /// <param name="target">The object to expose.</param> /// <remarks> /// This method can be used to restrict script access to the members of a particular /// interface or base class. /// <para> /// For information about the mapping between host members and script-callable properties /// and methods, see <see cref="AddHostObject(string, HostItemFlags, object)"/>. /// </para> /// </remarks> public void AddRestrictedHostObject <T>(string itemName, HostItemFlags flags, T target) { AddHostItem(itemName, flags, HostItem.Wrap(this, target, typeof(T))); }
/// <summary> /// Converts a type to a host type for use with script code running in the specified /// script engine. /// </summary> /// <param name="type">The type to convert to a host type.</param> /// <param name="engine">The script engine in which the host type will be used.</param> /// <returns>A host type for use with script code.</returns> public static object ToHostType(this Type type, ScriptEngine engine) { MiscHelpers.VerifyNonNullArgument(type, nameof(type)); MiscHelpers.VerifyNonNullArgument(engine, nameof(engine)); return(HostItem.Wrap(engine, HostType.Wrap(type))); }