本文整理汇总了C#中ScriptContext.CreateType方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptContext.CreateType方法的具体用法?C# ScriptContext.CreateType怎么用?C# ScriptContext.CreateType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptContext
的用法示例。
在下文中一共展示了ScriptContext.CreateType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
/// <summary>
/// Registers the module inside a script context.
/// </summary>
/// <param name="context">The context to register the module to.</param>
public void Register(ScriptContext context)
{
// Contains in F#: NaN
// Contains in F#: Infinity
// Contains in F#: undefined
// Contains in F#: eval
// Contains in F#: parseFloat
// Contains in F#: parseInt
// Contains in F#: isNaN
// Contains in F#: isFinite
// Contains in F#: decodeURI
// Contains in F#: decodeURIComponent
// Contains in F#: encodeURI
// Contains in F#: encodeURIComponent
// Create system types
context.CreateType<AppScope>("Application");
context.CreateType<SessionScope>("Session");
context.CreateType<PageScope>("Page");
context.CreateType<ConsoleObject>("Console", (prototype) => new ConsoleObject(prototype),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue>("info", ConsoleObject.Info),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue>("debug", ConsoleObject.Debug),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue>("log", ConsoleObject.Log),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue>("group", ConsoleObject.Group),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue>("groupCollapsed", ConsoleObject.GroupCollapsed),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue>("dir", ConsoleObject.Dir),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue>("time", ConsoleObject.Time),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue>("timeEnd", ConsoleObject.TimeEnd),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue>("warn", ConsoleObject.Warn),
context.CreateFunction<FunctionObject, ScriptObject>("groupEnd", ConsoleObject.GroupEnd)
);
context.CreateType<RemoteObject>("Remote", (prototype) => new RemoteObject(prototype),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue>("getHashCode", RemoteObject.GetHashCode),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue>("getAddress", RemoteObject.GetAddress),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue>("getConnectedOn", RemoteObject.GetConnectedOn),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue>("getConnectedFor", RemoteObject.GetConnectedFor)
);
// File: Static API
context.CreateType<FileObject>(FileObject.TypeName, (o) => new FileObject(o),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("appendLines", FileObject.AppendLines),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("appendText", FileObject.AppendText),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("appendJson", FileObject.AppendJson),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("writeLines", FileObject.WriteLines),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("writeText", FileObject.WriteText),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("writeJson", FileObject.WriteJson),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("writeBuffer", FileObject.WriteBuffer),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("readLines", FileObject.ReadLines),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("readJson", FileObject.ReadJson),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("readText", FileObject.ReadText),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readBuffer", FileObject.ReadBuffer),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("copy", FileObject.Copy),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("move", FileObject.Move),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("replace", FileObject.Replace),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("exists", FileObject.Exists),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("delete", FileObject.Delete)
);
// Timer: Delay Call
context.AttachFunction<FunctionObject, double, BoxedValue, BoxedValue, BoxedValue, ScriptObject>("setTimeout", Native.SetTimeout);
context.AttachFunction<BoxedValue>("clearTimeout", Native.ClearTimeout);
// Timer: Interval Call
context.AttachFunction<FunctionObject, double, BoxedValue, BoxedValue, BoxedValue, ScriptObject>("setInterval", Native.SetInterval);
context.AttachFunction<BoxedValue>("clearInterval", Native.ClearTimeout);
// Encoding: Base64
context.AttachFunction<BoxedValue, BoxedValue>("btoa", Native.BtoA);
context.AttachFunction<BoxedValue, BoxedValue>("atob", Native.AtoB);
// Network: Core
context.AttachFunction<BoxedValue, double, BoxedValue, string, BoxedValue>("transmitEvent", Native.TransmitEvent);
context.AttachFunction<BoxedValue, BoxedValue, string, BoxedValue>("transmitProperty", Native.TransmitProperty);
context.AttachFunction<BoxedValue, string, BoxedValue>("transmitConsole", Native.TransmitConsole);
// Buffer
context.CreateType<BufferObject, BoxedValue, BoxedValue>("Buffer", (o, param, encoding) => new BufferObject(o, param, encoding),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, string>("toString", BufferObject.ToString),
context.CreateFunction<FunctionObject, ScriptObject, string>("toJSON", BufferObject.ToJSON),
context.CreateFunction<FunctionObject, ScriptObject, string, BoxedValue, BoxedValue, BoxedValue, int>("write", BufferObject.Write),
context.CreateFunction<FunctionObject, ScriptObject, BufferObject, BoxedValue, BoxedValue, BoxedValue>("copy", BufferObject.Copy),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BufferObject>("slice", BufferObject.Slice),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("fill", BufferObject.Fill),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeUInt8", BufferObject.WriteUInt8),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeInt8", BufferObject.WriteInt8),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeUInt16BE", BufferObject.WriteUInt16BE),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeUInt32BE", BufferObject.WriteUInt32BE),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeUInt64BE", BufferObject.WriteUInt64BE),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeInt16BE", BufferObject.WriteInt16BE),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeInt32BE", BufferObject.WriteInt32BE),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeInt64BE", BufferObject.WriteInt64BE),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeFloatBE", BufferObject.WriteFloatBE),
context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeDoubleBE", BufferObject.WriteDoubleBE),
//.........这里部分代码省略.........