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


C# JsObject.TryGetProperty方法代码示例

本文整理汇总了C#中Jint.Native.JsObject.TryGetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# JsObject.TryGetProperty方法的具体用法?C# JsObject.TryGetProperty怎么用?C# JsObject.TryGetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Jint.Native.JsObject的用法示例。


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

示例1: IndexOfImpl

        /// <summary>
        /// 15.4.4.15
        /// </summary>
        /// <param name="target"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public JsInstance IndexOfImpl(JsObject target, JsInstance[] parameters) {
            if (parameters.Length == 0) {
                return Global.NumberClass.New(-1);
            }

            int len = (int)target["length"].ToNumber();
            if (len == 0)
                return Global.NumberClass.New(-1);
            int n = 0;
            if (parameters.Length > 1)
                n = Convert.ToInt32(parameters[1].ToNumber());
            int k;
            if (n >= len)
                return Global.NumberClass.New(-1);

            JsInstance searchParameter = parameters[0];
            if (n >= 0)
                k = n;
            else
                k = len - Math.Abs(n);
            while (k < len) {
                JsInstance result = null;
                if (target.TryGetProperty(k.ToString(), out result)) {
                    if (JsInstance.StrictlyEquals(Global, result, searchParameter) == Global.BooleanClass.True) {
                        return Global.NumberClass.New(k);
                    }
                }
                k++;
            }
            return Global.NumberClass.New(-1);
        }
开发者ID:robashton,项目名称:ravendb,代码行数:37,代码来源:JsArrayConstructor.cs

示例2: PutDocument

	    private void PutDocument(string key, JsObject doc, JsObject meta)
	    {
	        if (doc == null)
	        {
	            throw new InvalidOperationException(
	                string.Format("Created document cannot be null or empty. Document key: '{0}'", key));
	        }

            var newDocument = new JsonDocument
            {
                Key = key,
                DataAsJson = ToRavenJObject(doc)
            };
            
	        if (meta == null)
	        {
	            RavenJToken value;
	            if (newDocument.DataAsJson.TryGetValue("@metadata", out value))
	            {
	                newDocument.DataAsJson.Remove("@metadata");
	                newDocument.Metadata = (RavenJObject) value;
	            }
	        }
	        else
	        {
	            foreach (var etagKeyName in EtagKeyNames)
	            {
	                JsInstance result;
	                if (!meta.TryGetProperty(etagKeyName, out result))
	                    continue;
	                string etag = result.ToString();
	                meta.Delete(etagKeyName);
	                if (string.IsNullOrEmpty(etag))
	                    continue;
	                Etag newDocumentEtag;
	                if (Etag.TryParse(etag, out newDocumentEtag) == false)
	                {
	                    throw new InvalidOperationException(string.Format("Invalid ETag value '{0}' for document '{1}'",
	                                                                      etag, key));
	                }
	                newDocument.Etag = newDocumentEtag;
	            }
	            newDocument.Metadata = ToRavenJObject(meta);
	        }
	        ValidateDocument(newDocument);

            if(key == null || key.EndsWith("/"))
                createdDocIdentity.Add(newDocument);
            else 
                createdDocDict[key] = newDocument;
	    }
开发者ID:Nakro,项目名称:ravendb,代码行数:51,代码来源:ScriptedJsonPatcher.cs

示例3: LastIndexOfImpl

        /// <summary>
        /// 15.4.4.15
        /// </summary>
        /// <param name="target"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public JsInstance LastIndexOfImpl(JsObject target, JsInstance[] parameters) {
            if (parameters.Length == 0) {
                return Global.NumberClass.New(-1);
            }

            int len = target.Length;
            if (len == 0)
                return Global.NumberClass.New(-1);
            int n = len;
            if (parameters.Length > 1)
                n = Convert.ToInt32(parameters[1].ToNumber());
            int k;
            JsInstance searchParameter = parameters[0];
            if (n >= 0)
                k = Math.Min(n, len - 1);
            else
                k = len - Math.Abs(n - 1);
            while (k >= 0) {
                JsInstance result = null;
                if (target.TryGetProperty(k.ToString(), out result)) {
                    if (result == searchParameter) {
                        return Global.NumberClass.New(k);
                    }
                }
                k--;
            }
            return Global.NumberClass.New(-1);
        }
开发者ID:robashton,项目名称:ravendb,代码行数:34,代码来源:JsArrayConstructor.cs

示例4: UnShift

 /// <summary>
 /// 15.4.4.13
 /// </summary>
 /// <param name="target"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public JsInstance UnShift(JsObject target, JsInstance[] parameters) {
     for (int k = target.Length; k > 0; k--) {
         JsInstance result = null;
         string from = (k - 1).ToString();
         string to = (k + parameters.Length - 1).ToString();
         if (target.TryGetProperty(from, out result)) {
             target[to] = result;
         }
         else {
             target.Delete(to);
         }
     }
     List<JsInstance> items = new List<JsInstance>(parameters);
     for (int j = 0; items.Count > 0; j++) {
         JsInstance e = items[0];
         items.RemoveAt(0);
         target[j.ToString()] = e;
     }
     return Global.NumberClass.New(target.Length);
 }
开发者ID:robashton,项目名称:ravendb,代码行数:26,代码来源:JsArrayConstructor.cs

示例5: Splice

        /// <summary>
        /// 15.4.4.12
        /// </summary>
        /// <param name="target"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public JsInstance Splice(JsObject target, JsInstance[] parameters) {
            JsArray array = Global.ArrayClass.New();
            int relativeStart = Convert.ToInt32(parameters[0].ToNumber());
            int actualStart = relativeStart < 0 ? Math.Max(target.Length + relativeStart, 0) : Math.Min(relativeStart, target.Length);
            int actualDeleteCount = Math.Min(Math.Max(Convert.ToInt32(parameters[1].ToNumber()), 0), target.Length - actualStart);
            int len = target.Length;

            for (int k = 0; k < actualDeleteCount; k++) {
                string from = (relativeStart + k).ToString();
                JsInstance result = null;
                if (target.TryGetProperty(from, out result)) {
                    array.put(k, result);
                }
            }

            List<JsInstance> items = new List<JsInstance>();
            items.AddRange(parameters);
            items.RemoveAt(0);
            items.RemoveAt(0);

            // use non-distructional copy, determine direction
            if (items.Count < actualDeleteCount) {
                for (int k = actualStart; k < len - actualDeleteCount; k++) {
                    JsInstance result = null;
                    string from = (k + actualDeleteCount).ToString();
                    string to = (k + items.Count).ToString();
                    if (target.TryGetProperty(from, out result)) {
                        target[to] = result;
                    }
                    else {
                        target.Delete(to);
                    }
                }

                for (int k = target.Length; k > len - actualDeleteCount + items.Count; k--) {
                    target.Delete((k - 1).ToString());
                }

                target.Length = len - actualDeleteCount + items.Count;
            }
            else {
                for (int k = len - actualDeleteCount; k > actualStart; k--) {
                    JsInstance result = null;
                    string from = (k + actualDeleteCount - 1).ToString();
                    string to = (k + items.Count - 1).ToString();
                    if (target.TryGetProperty(from, out result)) {
                        target[to] = result;
                    }
                    else {
                        target.Delete(to);
                    }
                }


            }
            for (int k = 0; k < items.Count; k++)
                target[k.ToString()] = items[k];

            return array;
        }
开发者ID:robashton,项目名称:ravendb,代码行数:66,代码来源:JsArrayConstructor.cs

示例6: Reverse

        /// <summary>
        /// 15.4.4.8
        /// </summary>
        /// <param name="target"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public JsInstance Reverse(JsObject target, JsInstance[] parameters) {
            int len = target.Length;
            int middle = len / 2;

            for (int lower = 0; lower != middle; lower++) {
                int upper = len - lower - 1;
                string upperP = upper.ToString();
                string lowerP = lower.ToString();

                JsInstance lowerValue = null;
                JsInstance upperValue = null;
                bool lowerExists = target.TryGetProperty(lowerP, out lowerValue);
                bool upperExists = target.TryGetProperty(upperP, out upperValue);

                if (lowerExists) {
                    target[upperP] = lowerValue;
                }
                else {
                    target.Delete(upperP);
                }

                if (upperExists) {
                    target[lowerP] = upperValue;
                }
                else {
                    target.Delete(lowerP);
                }
            }
            return target;
        }
开发者ID:robashton,项目名称:ravendb,代码行数:36,代码来源:JsArrayConstructor.cs

示例7: Splice

        /// <summary>
        /// 15.4.4.12
        /// </summary>
        /// <param name="target"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public JsInstance Splice(JsObject target, JsInstance[] parameters)
        {
            JsArray array = Global.ArrayClass.New();
            int relativeStart = Convert.ToInt32(parameters[0].ToNumber());
            int actualStart = relativeStart < 0 ? Math.Max(target.Length + relativeStart, 0) : Math.Min(relativeStart, target.Length);
            int actualDeleteCount = Math.Min(Math.Max(Convert.ToInt32(parameters[1].ToNumber()), 0), target.Length - actualStart);
            int len = target.Length;

            for (int k = 0; k < actualDeleteCount; k++)
            {
                string from = (relativeStart + k).ToString();
                JsInstance result = null;
                if (target.TryGetProperty(from, out result))
                {
                    array.DefineOwnProperty(k.ToString(), new ValueDescriptor(target, k.ToString(), result));
                }
            }

            List<JsInstance> items = new List<JsInstance>();
            items.AddRange(parameters);
            items.RemoveAt(0);
            items.RemoveAt(0);
            if (items.Count < actualDeleteCount)
            {
                for (int k = actualStart; k < len - actualDeleteCount; k++)
                {
                    JsInstance result = null;
                    string from = (k + actualDeleteCount).ToString();
                    string to = (k + items.Count).ToString();
                    if (target.TryGetProperty(from, out result))
                    {
                        target[to] = result;
                    }
                    else
                    {
                        target.Delete(to);
                    }
                }
                for (int k = target.Length; k > len - actualDeleteCount + items.Count; k--)
                {
                    target.Delete((k - 1).ToString());
                }
            }
            else
            {
                for (int k = len - actualDeleteCount; k > actualStart; k--)
                {
                    JsInstance result = null;
                    string from = (k + actualDeleteCount - 1).ToString();
                    string to = (k + items.Count - 1).ToString();
                    if (target.TryGetProperty(from, out result))
                    {
                        target[to] = result;
                    }
                    else
                    {
                        target.Delete(to);
                    }
                }
                if (target.length != int.MinValue && target.Prototype != Prototype)
                    target.length += len - actualDeleteCount + items.Count;

                for (int k = 0; items.Count > 0; k++)
                {
                    JsInstance e = items[0];
                    items.RemoveAt(0);
                    target[k.ToString()] = e;
                }
            }
            return array;
        }
开发者ID:Fedorm,项目名称:core-master,代码行数:77,代码来源:JsArrayConstructor.cs


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