當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。