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


C# RavenJToken.Value方法代码示例

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


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

示例1: ExecuteInternal

		private static void ExecuteInternal(RavenJToken token, string prefix, Func<string, string, bool> loadId)
		{
			if (token == null)
				return; // nothing to do

			switch (token.Type)
			{
				case JTokenType.Array:
					foreach (var item in (RavenJArray)token)
					{
						ExecuteInternal(item, prefix, loadId);
					}
					break;
				case JTokenType.String:
			        var value = token.Value<string>();
                    if (loadId(value, null) == false)
                        loadId(value, prefix);
					break;
				case JTokenType.Integer:
					try
					{
						loadId(token.Value<long>().ToString(CultureInfo.InvariantCulture), prefix);
					}
					catch (OverflowException)
					{
						loadId(token.Value<ulong>().ToString(CultureInfo.InvariantCulture), prefix);
					}
					break;
				// here we ignore everything else
				// if it ain't a string or array, it is invalid
				// as an id
			}
		}
开发者ID:robashton,项目名称:ravendb,代码行数:33,代码来源:IncludesUtil.cs

示例2: TryGetUniqueValues

        public static bool TryGetUniqueValues(RavenJToken prop, out string[] uniqueValues)
        {
            if (prop == null || prop.Type == JTokenType.Null || (prop.Type == JTokenType.String && string.IsNullOrEmpty(prop.Value<string>())))
            {
                uniqueValues = null;
                return false;
            }

            var array = prop as RavenJArray;
            uniqueValues = array != null ? array.Select(p => p.Value<string>()).Where(x => !string.IsNullOrEmpty(x)).ToArray() : new[] { prop.Value<string>() };
            return true;
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:12,代码来源:Util.cs

示例3: GetConstraint

 public static UniqueConstraint GetConstraint(RavenJToken property)
 {
     switch (property.Type)
     {
         case JTokenType.String: // backward compatability
             return new UniqueConstraint { PropName = property.Value<string>() };
         case JTokenType.Object:
             return new UniqueConstraint { PropName = property.Value<string>("Name"), CaseInsensitive = property.Value<bool>("CaseInsensitive") };
         default:
             throw new ArgumentOutOfRangeException(property.Type.ToString());
     }
 }
开发者ID:j2jensen,项目名称:ravendb,代码行数:12,代码来源:Util.cs

示例4: ExecuteInternal

		private void ExecuteInternal(RavenJToken token, string prefix)
		{
			if (token == null)
				return; // nothing to do

			switch (token.Type)
			{
				case JTokenType.Array:
					foreach (var item in (RavenJArray)token)
					{
						ExecuteInternal(item, prefix);
					}
					break;
				case JTokenType.String:
					LoadId(token.Value<string>(), prefix);
					break;
				case JTokenType.Integer:
					LoadId(token.Value<int>().ToString(CultureInfo.InvariantCulture), prefix);
					break;
				default:
					// here we ignore everything else
					// if it ain't a string or array, it is invalid
					// as an id
					break;
			}
		}
开发者ID:robinminto,项目名称:ravendb,代码行数:26,代码来源:AddIncludesCommand.cs

示例5: ExecuteInternal

		private void ExecuteInternal(RavenJToken token)
		{
			if (token == null)
				return; // nothing to do

			switch (token.Type)
			{
				case JTokenType.Array:
					foreach (var item in (RavenJArray)token)
					{
						ExecuteInternal(item);
					}
					break;
				case JTokenType.String:
					var value = token.Value<string>();
					if (LoadedIds.Add(value) == false)
						return;
					var includedDoc = Database.Get(value, TransactionInformation);
					if (includedDoc != null)
						Add(includedDoc.Etag,includedDoc.ToJson());
					break;
				default:
					// here we ignore everything else
					// if it ain't a string or array, it is invalid
					// as an id
					break;
			}
		}
开发者ID:kblooie,项目名称:ravendb,代码行数:28,代码来源:AddIncludesCommand.cs

示例6: GetRoughSize

		/// <summary>
		/// gets rough size of RavenJToken - in bytes
		/// </summary>
		public  static long GetRoughSize(RavenJToken token)
		{
			long sum;
			switch (token.Type)
			{
				case JTokenType.None:
					return 0;
				case JTokenType.Object:
					sum = 2;// {}
					foreach (var prop in (RavenJObject)token)
					{
						sum += prop.Key.Length + 1; // name:
						sum += GetRoughSize(prop.Value);
					}
					return sum;
				case JTokenType.Array:
					// the 1 is for ,
					return 2 + ((RavenJArray)token).Sum(prop => 1 + GetRoughSize(prop));
				case JTokenType.Constructor:
				case JTokenType.Property:
				case JTokenType.Comment:
				case JTokenType.Raw:
					return 0;
				case JTokenType.Boolean:
					return token.Value<bool>() ? 4 : 5;
				case JTokenType.Null:
					return 4;
				case JTokenType.Undefined:
					return 9;
				case JTokenType.Date:
					return 21;
				case JTokenType.Bytes:
				case JTokenType.Integer:
				case JTokenType.Float:
				case JTokenType.String:
				case JTokenType.Guid:
				case JTokenType.TimeSpan:
				case JTokenType.Uri:
					return token.Value<string>().Length;
				default:
					throw new ArgumentOutOfRangeException();
			}
		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:46,代码来源:DocumentHelpers.cs

示例7: GetPropertyValue

		private static object GetPropertyValue(RavenJToken property)
		{
			switch (property.Type)
			{
				case JTokenType.Array:
				case JTokenType.Object:
					return property.ToString(Formatting.None);
				default:
					return property.Value<object>();
			}
		}
开发者ID:denno-secqtinstien,项目名称:ravendb,代码行数:11,代码来源:AnonymousObjectToLuceneDocumentConverter.cs

示例8: ExecuteInternal

		private static void ExecuteInternal(RavenJToken token, string prefix, Func<string, string, bool> loadId)
		{
			if (token == null)
				return; // nothing to do

			switch (token.Type)
			{
				case JTokenType.Array:
					foreach (var item in (RavenJArray)token)
					{
						ExecuteInternal(item, prefix, loadId);
					}
					break;
				case JTokenType.String:
			        var value = token.Value<string>();
                    // we need to check on both of them, with id & without id
                    // because people will do products/1 and detaisl/products/1 and want to be able
                    // to include on that
			        loadId(value, prefix);
					if (prefix != null)
						loadId(value, null);
					break;
				case JTokenType.Integer:
					try
					{
						loadId(token.Value<long>().ToString(CultureInfo.InvariantCulture), prefix);
					}
					catch (OverflowException)
					{
						loadId(token.Value<ulong>().ToString(CultureInfo.InvariantCulture), prefix);
					}
					break;
				// here we ignore everything else
				// if it ain't a string or array, it is invalid
				// as an id
			}
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:37,代码来源:IncludesUtil.cs

示例9: GetValue

        private object GetValue(RavenJToken token)
        {
            if (token is RavenJObject)
                return new RavenJObjectDataItem((RavenJObject)token);

            if (token is RavenJArray)
            {
                var jArray = (RavenJArray)token;
                var result = new object[jArray.Length];
                for (var index = 0; index < jArray.Length; ++index)
                    result[index] = GetValue(jArray[index]);
                return result;
            }

            return token.Value<object>();
        }
开发者ID:kingkino,项目名称:azure-documentdb-datamigrationtool,代码行数:16,代码来源:RavenJObjectDataItem.cs

示例10: ModifyValue

		private static void ModifyValue(PatchRequest patchCmd, string propName, RavenJToken property)
		{
			EnsurePreviousValueMatchCurrentValue(patchCmd, property);
			if (property == null)
				throw new InvalidOperationException("Cannot modify value from '" + propName + "' because it was not found");

			var nestedCommands = patchCmd.Nested;
			if (nestedCommands == null)
				throw new InvalidOperationException("Cannot understand modified value from '" + propName +
													"' because could not find nested array of commands");

			var arrayOrValue = TryGetArray(property) ?? property;
			switch (arrayOrValue.Type)
			{
				case JTokenType.Object:
					foreach (var cmd in nestedCommands)
					{
						var nestedDoc = property.Value<RavenJObject>();
						new JsonPatcher(nestedDoc).Apply(cmd);
					}
					break;
				case JTokenType.Array:
					var position = patchCmd.Position;
					var allPositionsIsSelected = patchCmd.AllPositions.HasValue ? patchCmd.AllPositions.Value : false;
					if (position == null && !allPositionsIsSelected)
						throw new InvalidOperationException("Cannot modify value from  '" + propName +
						                                    "' because position element does not exists or not an integer and allPositions is not set");
					var valueList = new List<RavenJToken>();
					if (allPositionsIsSelected)
					{
						valueList.AddRange(arrayOrValue.Values<RavenJToken>());
					}
					else
					{
						valueList.Add(((RavenJArray)arrayOrValue)[position.Value]);
					}

					foreach (var value in valueList)
					{
						foreach (var cmd in nestedCommands)
						{
							new JsonPatcher(value.Value<RavenJObject>()).Apply(cmd);
						}
					}
					break;
				default:
					throw new InvalidOperationException("Can't understand how to deal with: " + property.Type);
			}
		}
开发者ID:neiz,项目名称:ravendb,代码行数:49,代码来源:JsonPatcher.cs

示例11: PutTransformer

		protected async override Task PutTransformer(string transformerName, RavenJToken transformer)
		{
			if (IsTransformersSupported == false)
				return;

			if (transformer != null)
			{
				var transformerDefinition = JsonConvert.DeserializeObject<TransformerDefinition>(transformer.Value<RavenJObject>("definition").ToString());
				await Commands.PutTransformerAsync(transformerName, transformerDefinition);
			}

			await FlushBatch();
		}
开发者ID:KyleGobel,项目名称:ravendb,代码行数:13,代码来源:SmugglerApi.cs

示例12: PutIndex

		protected override Task PutIndex(string indexName, RavenJToken index)
		{
			if (index != null)
			{
				var indexDefinition =
					JsonConvert.DeserializeObject<IndexDefinition>(index.Value<RavenJObject>("definition").ToString());

				return commands.PutIndexAsync(indexName, indexDefinition, overwrite: true);
			}

			return FlushBatch();
		}
开发者ID:robashton,项目名称:ravendb,代码行数:12,代码来源:SmugglerApi.cs

示例13: PutTransformer

        public async Task PutTransformer(string transformerName, RavenJToken transformer)
        {
            if (isTransformersSupported() == false)
                return;

            if (transformer != null)
            {
                var transformerDefinition = JsonConvert.DeserializeObject<TransformerDefinition>(transformer.Value<RavenJObject>("definition").ToString());
                await Store.AsyncDatabaseCommands.PutTransformerAsync(transformerName, transformerDefinition);
            }
        }
开发者ID:knives-out,项目名称:ravendb,代码行数:11,代码来源:SmugglerRemoteDatabaseOperations.cs

示例14: AssertNoPropertyBeyondSize

		public void AssertNoPropertyBeyondSize(RavenJToken token, int maxSize, string path = "")
		{
			if (path.StartsWith("."))
				path = path.Substring(1);
			switch (token.Type)
			{
				case JTokenType.Object:
					foreach (var item in ((RavenJObject)token))
					{
						if (item.Key != null && item.Key.Length > maxSize)
							throw new InvalidOperationException(string.Format("Document's property Name: \"{0}\" is too long to view in the studio (property length: {1:#,#}, max allowed length: {2:#,#})", path + "." + item.Key, item.Key.Length, maxSize));
						AssertNoPropertyBeyondSize(item.Value, maxSize, path + "." + item.Key);
					}
					break;
				case JTokenType.Array:
					foreach (var item in ((RavenJArray)token))
					{
						AssertNoPropertyBeyondSize(item, maxSize, path + ".");
					}
					break;
				case JTokenType.String:
					var value = token.Value<string>();
					if (value != null && value.Length > maxSize)
						throw new InvalidOperationException(string.Format("Document's property: \"{0}\" is too long to view in the studio (property length: {1:#,#}, max allowed length: {2:#,#})", path, value.Length, maxSize));
					break;
			}
		}
开发者ID:samueldjack,项目名称:ravendb,代码行数:27,代码来源:EditableDocumentModel.cs

示例15: GetTokenValue

        private static object GetTokenValue(RavenJToken token)
        {
            if (token == null)
            {
                return "";
            }

            switch (token.Type)
            {
                case JTokenType.Object:
                case JTokenType.Array:
                case JTokenType.Constructor:
                case JTokenType.Property:
                case JTokenType.Comment:
                case JTokenType.Raw:
                case JTokenType.Bytes:
                case JTokenType.Uri:
                    return token.ToString(Formatting.None);
                case JTokenType.Integer:
                    return token.Value<int>();
                case JTokenType.Float:
                    return token.Value<double>();
                case JTokenType.String:
                    return token.Value<string>();
                case JTokenType.Boolean:
                    return token.Value<bool>();
                case JTokenType.Date:
                    return token.Value<DateTime>();
                case JTokenType.Guid:
                    return token.Value<Guid>();
                case JTokenType.TimeSpan:
                    return token.Value<TimeSpan>();
                default:
                    return "";
            }
        }
开发者ID:925coder,项目名称:ravendb,代码行数:36,代码来源:ColumnModelBindingExtensions.cs


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