当前位置: 首页>>代码示例>>C#>>正文


C# BoxedValue类代码示例

本文整理汇总了C#中BoxedValue的典型用法代码示例。如果您正苦于以下问题:C# BoxedValue类的具体用法?C# BoxedValue怎么用?C# BoxedValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BoxedValue类属于命名空间,在下文中一共展示了BoxedValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToBoolean

        public static bool ToBoolean(BoxedValue v)
        {
            switch (v.Tag)
            {
                case TypeTags.Bool:
                    return v.Bool;

                case TypeTags.String:
                    return !string.IsNullOrEmpty(v.String);

                case TypeTags.SuffixString:
                    var ss = (SuffixString)v.Clr;
                    return ss.Length > 0;

                case TypeTags.Undefined:
                    return false;

                case TypeTags.Clr:
                    return v.Clr != null;

                case TypeTags.Object:
                case TypeTags.Function:
                    return true;

                default:
                    return ToBoolean(v.Number);
            }
        }
开发者ID:mizzunet,项目名称:spike-box,代码行数:28,代码来源:TypeConverter.cs

示例2: AppendJson

        /// <summary>
        /// Opens a file, appends the specified string to the file, and then closes the file. If the file does not exist, this method creates a file, writes the specified string to the file, then closes the file.
        /// </summary>
        internal static void AppendJson(FunctionObject ctx, ScriptObject instance, BoxedValue path, BoxedValue contents, BoxedValue onComplete, BoxedValue encodingName)
        {
            if (!path.IsString)
                throw new ArgumentException("[appendJson] First parameter should be defined and be a string.");
            if (!contents.IsStrictlyObject)
                throw new ArgumentException("[appendJson] Second parameter should be defined and be an object.");
            if (!onComplete.IsUndefined && !onComplete.IsFunction)
                throw new ArgumentException("[appendJson] Third parameter should be an onComplete function.");

            // Get the curent channel
            var channel = Channel.Current;

            // Dispatch the task
            channel.Async(() =>
            {
                // The encoding to use
                Encoding encoding = encodingName.IsString
                    ? TextEncoding.GetEncoding(encodingName.String)
                    : null;

                // Defaults to UTF8
                if (encoding == null)
                    encoding = TextEncoding.UTF8;

                // Unbox the array of lines and execute the append
                File.AppendAllText(
                    path.Unbox<string>(),
                    Native.Serialize(instance.Env, contents, false).Unbox<string>(),
                    encoding
                    );

                // Dispatch the on complete asynchronously
                channel.DispatchCallback(onComplete, instance);
            });
        }
开发者ID:mizzunet,项目名称:spike-box,代码行数:38,代码来源:FileObject.cs

示例3: UserError

 public UserError(BoxedValue value, int line, int column)
     : base(TypeConverter.ToString(value))
 {
     Value = value;
     Line = line;
     Column = column;
 }
开发者ID:RainsSoft,项目名称:IronJS,代码行数:7,代码来源:Errors.cs

示例4: SendEvent

        /// <summary>
        /// Represents low-level networking call that can be used to transmit an event to the browser.
        /// </summary>
        /// <param name="client">The client to transmit the event to.</param>
        /// <param name="propertyName">The name of the event to transmit.</param>
        /// <param name="type">The type of the event to transmit.</param>
        /// <param name="eventValue">The value of the event to transmit.</param>
        internal static void SendEvent(ClientObject client, AppEventType type, BoxedValue target, string eventName, BoxedValue eventValue)
        {
            try
            {
                // Check if the target is an object and retrieve the id.
                var oid = 0;
                if (target.IsObject && target.Object is BaseObject)
                    oid = ((BaseObject)target.Object).Oid;

                // Get the client
                var channel = client.Target;

                // Convert to a string
                var stringValue = TypeConverter.ToNullableString(
                    Native.Serialize(client.Env, eventValue, true)
                    );

                // Dispatch the inform
                channel.TransmitEvent(type, oid, eventName, stringValue);
            }
            catch (Exception ex)
            {
                // Log the exception
                Service.Logger.Log(ex);
            }
        }
开发者ID:mizzunet,项目名称:spike-box,代码行数:33,代码来源:Native.Network.cs

示例5: OnPropertyChange

        /// <summary>
        /// Represents an event fired when a script object property has been changed.
        /// </summary>
        /// <param name="instance">The instance of the script object that contains the property.</param>
        /// <param name="changeType">The type of the change.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="newValue">The new value of the property.</param>
        /// <param name="oldValue">The old value of the property.</param>
        public static void OnPropertyChange(ScriptObject instance, PropertyChangeType changeType, string propertyName, BoxedValue newValue, BoxedValue oldValue)
        {
            // Ignore identifier property
            if (propertyName == "$i")
                return;

            switch (changeType)
            {
                // Occurs when a new property is assigned to an object, either by
                // using the indexer, property access or array methods.
                case PropertyChangeType.Put:
                {
                    // We need to make sure the new value is marked as observed
                    // as well, so its members will notify us too.
                    if (newValue.IsStrictlyObject)
                        newValue.Object.Observe();

                    // Send the change through the current scope
                    Channel.Current.SendPropertyChange(PropertyChangeType.Put, instance.Oid, propertyName, newValue);
                    break;
                }

                // Occurs when a property change occurs, by using an assignment
                // operator, or the array indexer.
                case PropertyChangeType.Set:
                {
                    // We need to unmark the old value and ignore it, as we no
                    // longer require observations from that value.
                    if (oldValue.IsStrictlyObject)
                        oldValue.Object.Ignore();

                    // We need to make sure the new value is marked as observed
                    // as well, so its members will notify us too.
                    if (newValue.IsStrictlyObject)
                        newValue.Object.Observe();

                    // Send the change through the current scope
                    Channel.Current.SendPropertyChange(PropertyChangeType.Set, instance.Oid, propertyName, newValue);
                    break;
                }

                // Occurs when a property was deleted from the object, either by
                // using a 'delete' keyword or the array removal methods.
                case PropertyChangeType.Delete:
                {
                    // We need to unmark the old value and ignore it, as we no
                    // longer require observations from that value.
                    if (oldValue.IsStrictlyObject)
                        oldValue.Object.Ignore();

                    // Send the change through the current scope
                    Channel.Current.SendPropertyChange(PropertyChangeType.Delete, instance.Oid, propertyName, newValue);
                    break;
                }

            }

            //Console.WriteLine("Observe: [{0}] {1} = {2}", changeType.ToString(), propertyName, propertyValue);
        }
开发者ID:mizzunet,项目名称:spike-box,代码行数:67,代码来源:Native.Observe.cs

示例6: GetPathOf

        private static BoxedValue GetPathOf(BoxedValue path)
        {
            var filePath = TypeConverter.ToString(path);
            var file = new FileInfo(filePath);
            var directory = file.DirectoryName;

            return TypeConverter.ToBoxedValue(directory);
        }
开发者ID:jamarchist,项目名称:JSBuild,代码行数:8,代码来源:PathOf.cs

示例7: TaskFunction

        public static void TaskFunction(BoxedValue options)
        {
            var paths = options.ComplexProperty("Paths").ToArray<string>();
            var numberOfRetries = options.SimpleProperty<double>("NumberOfRetries");

            System.Console.WriteLine(numberOfRetries);
            TaskFunction(paths);
        }
开发者ID:jamarchist,项目名称:JSBuild,代码行数:8,代码来源:Delete.cs

示例8: Put

 public override sealed void Put(string name, BoxedValue value)
 {
     int index = 0;
     if (this.CanPut(name, out index))
     {
         this.Properties[index].Value = value;
         this.Properties[index].HasValue = true;
     }
 }
开发者ID:mizzunet,项目名称:spike-box,代码行数:9,代码来源:ValueObject.cs

示例9: ArgumentsObject

 /// <summary>
 /// Initializes a new instance of the <see cref="ArgumentsObject"/> class.
 /// </summary>
 /// <param name="env">The environment.</param>
 /// <param name="linkMap">The link map.</param>
 /// <param name="privateScope">The private scope.</param>
 /// <param name="sharedScope">The shared scope.</param>
 public ArgumentsObject(
     Environment env,
     ArgLink[] linkMap,
     BoxedValue[] privateScope,
     BoxedValue[] sharedScope)
     : base(env, env.Maps.Base, env.Prototypes.Object)
 {
     PrivateScope = privateScope;
     SharedScope = sharedScope;
     LinkMap = linkMap;
 }
开发者ID:RainsSoft,项目名称:IronJS,代码行数:18,代码来源:ArgumentsObject.cs

示例10: GetDirectoryFiles

        private BoxedValue GetDirectoryFiles(BoxedValue options)
        {
            var directoryPath = options.SimpleProperty<string>("directory");

            var searchPattern = "*.*";
            if (options.Has("pattern")) searchPattern = options.SimpleProperty<string>("pattern");

            var recurse = SearchOption.TopDirectoryOnly;
            if (options.Has("recurse")) recurse = SearchOption.AllDirectories;

            var files = Directory.GetFiles(directoryPath, searchPattern, recurse);

            return files.ToBoxedValue(context.Environment);
        }
开发者ID:jamarchist,项目名称:JSBuild,代码行数:14,代码来源:GetFiles.cs

示例11:

 /// <summary>
 /// Implements the binary `in` operator.
 /// </summary>
 public static bool @in(Environment env, BoxedValue l, BoxedValue r)
 {
     if (!r.IsObject)
     {
         return env.RaiseTypeError<bool>("Right operand is not a object");
     }
     uint index = 0;
     if (TypeConverter.TryToIndex(l, out index))
     {
         return r.Object.Has(index);
     }
     string name = TypeConverter.ToString(l);
     return r.Object.Has(name);
 }
开发者ID:RainsSoft,项目名称:IronJS,代码行数:17,代码来源:Operators.cs

示例12: BufferObject

        /// <summary>
        /// Creates a new instance of an object.
        /// </summary>
        /// <param name="prototype">The prototype to use.</param>
        /// <param name="param">Either the size of the buffer, a string or the array of octets.</param>
        /// <param name="encodingName">The encoding of a string.</param>
        public BufferObject(ScriptObject prototype, BoxedValue param, BoxedValue encodingName)
            : base(prototype)
        {
            if (param.IsNumber)
            {
                // Create a new array with the provided size
                this.Buffer = new ArraySegment<byte>(
                    new byte[(int)param.Number]
                    );
                this.Put("length", this.Buffer.Count, DescriptorAttrs.ReadOnly);
                return;
            }

            if (param.IsString)
            {
                // The encoding to use
                Encoding encoding = encodingName.IsString
                    ? TextEncoding.GetEncoding(encodingName.String)
                    : null;

                // Defaults to UTF8
                if (encoding == null)
                    encoding = TextEncoding.UTF8;

                // Decode
                this.Buffer = new ArraySegment<byte>(encoding.GetBytes(param.String));
                this.Put("length", this.Buffer.Count, DescriptorAttrs.ReadOnly);
                return;
            }

            if (param.IsStrictlyObject && param.Object is ArrayObject)
            {
                // Allocate a new array
                var bytes = (param.Object as ArrayObject);
                this.Buffer = new ArraySegment<byte>(new byte[bytes.Length]);
                this.Put("length", this.Buffer.Count, DescriptorAttrs.ReadOnly);

                // Iterate through the array and convert each integer to a byte
                for (int i = 0; i < bytes.Length; ++i)
                {
                    // Get the number and convert to byte
                    var item = bytes.Get(i);
                    if (item.IsNumber)
                        this.Buffer.Array[i] = Convert.ToByte(item.Number);
                }
            }
        }
开发者ID:mizzunet,项目名称:spike-box,代码行数:53,代码来源:BufferObject.cs

示例13: add

        /// <summary>
        /// Implements the binary `+` operator.
        /// </summary>
        public static BoxedValue add(BoxedValue l, BoxedValue r)
        {
            if (l.Tag == TypeTags.SuffixString)
            {
                var newString = SuffixString.Concat(
                    l.SuffixString,
                    TypeConverter.ToString(TypeConverter.ToPrimitive(r)));

                return BoxedValue.Box(newString);
            }

            if (l.Tag == TypeTags.String ||
                r.Tag == TypeTags.String ||
                r.Tag == TypeTags.SuffixString)
            {
                var newString = SuffixString.Concat(
                    TypeConverter.ToString(TypeConverter.ToPrimitive(l)),
                    TypeConverter.ToString(TypeConverter.ToPrimitive(r)));

                return BoxedValue.Box(newString);
            }

            var lPrim = TypeConverter.ToPrimitive(l);
            var rPrim = TypeConverter.ToPrimitive(r);

            if (lPrim.Tag == TypeTags.SuffixString)
            {
                var newString = SuffixString.Concat(
                    lPrim.SuffixString,
                    TypeConverter.ToString(rPrim));

                return BoxedValue.Box(newString);
            }

            if (lPrim.Tag == TypeTags.String ||
                rPrim.Tag == TypeTags.String ||
                rPrim.Tag == TypeTags.SuffixString)
            {
                var newString = SuffixString.Concat(
                    TypeConverter.ToString(lPrim),
                    TypeConverter.ToString(rPrim));

                return BoxedValue.Box(newString);
            }

            return BoxedValue.Box(TypeConverter.ToNumber(lPrim) + TypeConverter.ToNumber(rPrim));
        }
开发者ID:RainsSoft,项目名称:IronJS,代码行数:50,代码来源:Operators.cs

示例14: gt

 /// <summary>
 /// Implements the binary `&gt;` operator.
 /// </summary>
 public static bool gt(BoxedValue l, BoxedValue r)
 {
     return Compare(l, r, true,
         (a, b) => string.CompareOrdinal(a, b) > 0,
         (a, b) => a > b);
 }
开发者ID:RainsSoft,项目名称:IronJS,代码行数:9,代码来源:Operators.cs

示例15: Compare

        /// <summary>
        /// Supports the binary comparison operators.
        /// </summary>
        private static bool Compare(BoxedValue l, BoxedValue r, bool rightToLeft, Func<string, string, bool> stringCompare, Func<double, double, bool> numberCompare)
        {
            if ((l.Tag == TypeTags.String || l.Tag == TypeTags.SuffixString) &&
                (r.Tag == TypeTags.String || r.Tag == TypeTags.SuffixString))
            {
                return stringCompare(
                    l.Clr.ToString(),
                    r.Clr.ToString());
            }

            if (l.IsNumber && r.IsNumber)
            {
                return numberCompare(
                    l.Number,
                    r.Number);
            }

            BoxedValue lPrim, rPrim;
            if (rightToLeft)
            {
                rPrim = TypeConverter.ToPrimitive(r, DefaultValueHint.Number);
                lPrim = TypeConverter.ToPrimitive(l, DefaultValueHint.Number);
            }
            else
            {
                lPrim = TypeConverter.ToPrimitive(l, DefaultValueHint.Number);
                rPrim = TypeConverter.ToPrimitive(r, DefaultValueHint.Number);
            }

            if ((lPrim.Tag == TypeTags.String || lPrim.Tag == TypeTags.SuffixString) &&
                (rPrim.Tag == TypeTags.String || rPrim.Tag == TypeTags.SuffixString))
            {
                return stringCompare(
                    lPrim.Clr.ToString(),
                    rPrim.Clr.ToString());
            }

            var lNum = TypeConverter.ToNumber(lPrim);
            var rNum = TypeConverter.ToNumber(rPrim);
            return numberCompare(
                lNum,
                rNum);
        }
开发者ID:RainsSoft,项目名称:IronJS,代码行数:46,代码来源:Operators.cs


注:本文中的BoxedValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。