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


C# JToken.IsNull方法代码示例

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


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

示例1: ValidateTypeValue

 /// <summary>Throws an exception if the given value is not a valid @type value.</summary>
 /// <remarks>Throws an exception if the given value is not a valid @type value.</remarks>
 /// <param name="v">the value to check.</param>
 /// <exception cref="JsonLdError">JsonLdError</exception>
 /// <exception cref="JsonLD.Core.JsonLdError"></exception>
 internal static bool ValidateTypeValue(JToken v)
 {
     if (v.IsNull())
     {
         throw new ArgumentNullException("\"@type\" value cannot be null");
     }
     // must be a string, subject reference, or empty object
     if (v.Type == JTokenType.String || (v is JObject && (((JObject)v).ContainsKey
         ("@id") || ((JArray)v).Count == 0)))
     {
         return true;
     }
     // must be an array
     bool isValid = false;
     if (v is JArray)
     {
         isValid = true;
         foreach (JToken i in (JArray)v)
         {
             if (!(i.Type == JTokenType.String || i is JObject && ((JObject)i).ContainsKey
                 ("@id")))
             {
                 isValid = false;
                 break;
             }
         }
     }
     if (!isValid)
     {
         throw new JsonLdError(JsonLdError.Error.SyntaxError);
     }
     return true;
 }
开发者ID:NuGet,项目名称:json-ld.net,代码行数:38,代码来源:JsonLdUtils.cs

示例2: Expand

		/// <summary>
		/// Expansion Algorithm
		/// http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithm
		/// </summary>
		/// <param name="activeCtx"></param>
		/// <param name="activeProperty"></param>
		/// <param name="element"></param>
		/// <returns></returns>
		/// <exception cref="JsonLdError">JsonLdError</exception>
		/// <exception cref="JsonLD.Core.JsonLdError"></exception>
		public virtual JToken Expand(Context activeCtx, string activeProperty, JToken element
			)
		{
			// 1)
			if (element.IsNull())
			{
				return null;
			}
			// 3)
			if (element is JArray)
			{
				// 3.1)
                JArray result = new JArray();
				// 3.2)
                foreach (JToken item in (JArray)element)
				{
					// 3.2.1)
					JToken v = Expand(activeCtx, activeProperty, item);
					// 3.2.2)
					if (("@list".Equals(activeProperty) || "@list".Equals(activeCtx.GetContainer(activeProperty
						))) && (v is JArray || (v is JObject && ((IDictionary<string, JToken>)v).ContainsKey
						("@list"))))
					{
						throw new JsonLdError(JsonLdError.Error.ListOfLists, "lists of lists are not permitted."
							);
					}
					else
					{
						// 3.2.3)
						if (!v.IsNull())
						{
							if (v is JArray)
							{
								JsonLD.Collections.AddAll(result, (JArray)v);
							}
							else
							{
								result.Add(v);
							}
						}
					}
				}
				// 3.3)
				return result;
			}
			else
			{
				// 4)
				if (element is JObject)
				{
					// access helper
                    IDictionary<string, JToken> elem = (JObject)element;
					// 5)
					if (elem.ContainsKey("@context"))
					{
						activeCtx = activeCtx.Parse(elem["@context"]);
					}
					// 6)
                    JObject result = new JObject();
					// 7)
                    JArray keys = new JArray(element.GetKeys());
					keys.SortInPlace();
					foreach (string key in keys)
					{
						JToken value = elem[key];
						// 7.1)
						if (key.Equals("@context"))
						{
							continue;
						}
						// 7.2)
						string expandedProperty = activeCtx.ExpandIri(key, false, true, null, null);
                        JToken expandedValue = null;
						// 7.3)
						if (expandedProperty == null || (!expandedProperty.Contains(":") && !JsonLdUtils.IsKeyword
							(expandedProperty)))
						{
							continue;
						}
						// 7.4)
						if (JsonLdUtils.IsKeyword(expandedProperty))
						{
							// 7.4.1)
							if ("@reverse".Equals(activeProperty))
							{
								throw new JsonLdError(JsonLdError.Error.InvalidReversePropertyMap, "a keyword cannot be used as a @reverse propery"
									);
							}
							// 7.4.2)
							if (result.ContainsKey(expandedProperty))
//.........这里部分代码省略.........
开发者ID:hydrojumbo,项目名称:json-ld.net,代码行数:101,代码来源:JsonLdApi.cs

示例3: RemoveBase

 public static string RemoveBase(JToken baseobj, string iri)
 {
     if (baseobj.IsNull())
     {
         return iri;
     }
     URL @base;
     if (baseobj.Type == JTokenType.String)
     {
         @base = URL.Parse((string)baseobj);
     }
     else
     {
         throw new Exception("Arrgggghhh!");
         //@base = (URL)baseobj;
     }
     // establish base root
     string root = string.Empty;
     if (!string.Empty.Equals(@base.href))
     {
         root += (@base.protocol) + "//" + @base.authority;
     }
     else
     {
         // support network-path reference with empty base
         if (iri.IndexOf("//") != 0)
         {
             root += "//";
         }
     }
     // IRI not relative to base
     if (iri.IndexOf(root) != 0)
     {
         return iri;
     }
     // remove root from IRI and parse remainder
     URL rel = URL.Parse(JsonLD.JavaCompat.Substring(iri, root.Length));
     // remove path segments that match
     IList<string> baseSegments = new List<string>(System.Linq.Enumerable.ToList(@base
         .normalizedPath.Split("/")));
     baseSegments = baseSegments.Where(seg => seg != "").ToList();
     if (@base.normalizedPath.EndsWith("/"))
     {
         baseSegments.Add(string.Empty);
     }
     IList<string> iriSegments = new List<string>(System.Linq.Enumerable.ToList(rel.normalizedPath
         .Split("/")));
     iriSegments = iriSegments.Where(seg => seg != "").ToList();
     if (rel.normalizedPath.EndsWith("/"))
     {
         iriSegments.Add(string.Empty);
     }
     while (baseSegments.Count > 0 && iriSegments.Count > 0)
     {
         if (!baseSegments[0].Equals(iriSegments[0]))
         {
             break;
         }
         if (baseSegments.Count > 0)
         {
             baseSegments.RemoveAt(0);
         }
         if (iriSegments.Count > 0)
         {
             iriSegments.RemoveAt(0);
         }
     }
     // use '../' for each non-matching base segment
     string rval = string.Empty;
     if (baseSegments.Count > 0)
     {
         // don't count the last segment if it isn't a path (doesn't end in
         // '/')
         // don't count empty first segment, it means base began with '/'
         if ([email protected]("/") || string.Empty.Equals(baseSegments[0]))
         {
             baseSegments.RemoveAt(baseSegments.Count - 1);
         }
         for (int i = 0; i < baseSegments.Count; ++i)
         {
             rval += "../";
         }
     }
     // prepend remaining segments
     if (iriSegments.Count > 0)
     {
         rval += iriSegments[0];
     }
     for (int i_1 = 1; i_1 < iriSegments.Count; i_1++)
     {
         rval += "/" + iriSegments[i_1];
     }
     // add query and hash
     if (!string.Empty.Equals(rel.query))
     {
         rval += "?" + rel.query;
     }
     if (!string.Empty.Equals(rel.hash))
     {
         rval += rel.hash;
//.........这里部分代码省略.........
开发者ID:milanjezek,项目名称:json-ld.net,代码行数:101,代码来源:URL.cs

示例4: GenerateNodeMap

		/// <exception cref="JsonLD.Core.JsonLdError"></exception>
        internal virtual void GenerateNodeMap(JToken element, JObject
             nodeMap, string activeGraph, JToken activeSubject, string activeProperty, JObject list)
		{
			// 1)
			if (element is JArray)
			{
				// 1.1)
				foreach (JToken item in (JArray)element)
				{
					GenerateNodeMap(item, nodeMap, activeGraph, activeSubject, activeProperty, list);
				}
				return;
			}
			// for convenience
            IDictionary<string, JToken> elem = (IDictionary<string, JToken>)element;
			// 2)
			if (!((IDictionary<string,JToken>)nodeMap).ContainsKey(activeGraph))
			{
				nodeMap[activeGraph] = new JObject();
			}
            JObject graph = (JObject)nodeMap[activeGraph
				];
            JObject node = (JObject)((activeSubject.IsNull() || activeSubject.Type != JTokenType.String) 
                ? null : graph[(string)activeSubject]);
			// 3)
			if (elem.ContainsKey("@type"))
			{
				// 3.1)
				JArray oldTypes;
                JArray newTypes = new JArray();
                if (elem["@type"] is JArray)
				{
                    oldTypes = (JArray)elem["@type"];
				}
				else
				{
                    oldTypes = new JArray();
					oldTypes.Add((string)elem["@type"]);
				}
				foreach (string item in oldTypes)
				{
					if (item.StartsWith("_:"))
					{
						newTypes.Add(GenerateBlankNodeIdentifier(item));
					}
					else
					{
						newTypes.Add(item);
					}
				}
				if (elem["@type"] is JArray)
				{
					elem["@type"] = newTypes;
				}
				else
				{
					elem["@type"] = newTypes[0];
				}
			}
			// 4)
			if (elem.ContainsKey("@value"))
			{
				// 4.1)
				if (list == null)
				{
					JsonLdUtils.MergeValue(node, activeProperty, (JObject)elem);
				}
				else
				{
					// 4.2)
					JsonLdUtils.MergeValue(list, "@list", (JObject)elem);
				}
			}
			else
			{
				// 5)
				if (elem.ContainsKey("@list"))
				{
					// 5.1)
					JObject result = new JObject();
					result["@list"] = new JArray();
					// 5.2)
					//for (final Object item : (List<Object>) elem.get("@list")) {
					//    generateNodeMap(item, nodeMap, activeGraph, activeSubject, activeProperty, result);
					//}
					GenerateNodeMap(elem["@list"], nodeMap, activeGraph, activeSubject, activeProperty
						, result);
					// 5.3)
					JsonLdUtils.MergeValue(node, activeProperty, result);
				}
				else
				{
					// 6)
					// 6.1)
					string id = (string)JsonLD.Collections.Remove(elem, "@id");
					if (id != null)
					{
						if (id.StartsWith("_:"))
						{
//.........这里部分代码省略.........
开发者ID:hydrojumbo,项目名称:json-ld.net,代码行数:101,代码来源:JsonLdApi.cs


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