/// <summary>
        /// Converts an object to a <see cref="JsonValue"/>.
        /// </summary>
        /// <param name="serializer">The <see cref="JsonSerializer"/> instance to use for additional
        /// serialization of values.</param>
        /// <returns>The <see cref="JsonValue"/> representation of the object.</returns>
        public JsonValue ToJson(JsonSerializer serializer)
        {
            var obj = new JsonObject();

            obj["valid"] = IsValid;
            if (RelativeLocation != null)
            {
                var relativeLocation = RelativeLocation.ToString();
                obj["keywordLocation"] = relativeLocation;
                if (AbsoluteLocation != null && (AbsoluteLocation.Fragment != relativeLocation ||
                                                 RelativeLocation.Contains("$ref") ||
                                                 RelativeLocation.Contains("$recursiveRef")))
                {
                    obj["absoluteKeywordLocation"] = AbsoluteLocation.OriginalString;
                }
            }
            if (InstanceLocation != null)
            {
                obj["instanceLocation"] = InstanceLocation.ToString();
            }

            var nonNullNestedResults = NestedResults.Where(r => !ReferenceEquals(r, Null)).ToList();

            if (Keyword != null)
            {
                obj["keyword"] = Keyword;
            }
            if (IsValid)
            {
                if (AnnotationValue != null)
                {
                    obj["annotation"] = AnnotationValue;
                }
                if (nonNullNestedResults.Any())
                {
                    obj["annotations"] = nonNullNestedResults.Select(r => r.ToJson(serializer)).ToJson();
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(ErrorMessage))
                {
                    obj["error"] = ErrorMessage;
                }
                if (nonNullNestedResults.Any())
                {
                    obj["errors"] = nonNullNestedResults.Select(r => r.ToJson(serializer)).ToJson();
                }
            }
            if (IncludeAdditionalInfo && AdditionalInfo != null && AdditionalInfo.Any())
            {
                obj["additionalInfo"] = AdditionalInfo;
            }

            return(obj);
        }
示例#2
0
 protected CatalogSubject(SystemResourceScheme Scheme, string host, string Name, INodeCatalogSubject Parent = null)
 {
     this.Parent           = Parent;
     this.Scheme           = Scheme;
     this.IsRoot           = Parent == null;
     this.SymbolicHost     = host;
     this.Name             = IsRoot ? $"/{host}/{Name}" : Name;
     this.Lineage          = DeriveLineage().ToList();
     this.RelativeLocation = IsRoot ? this.Name : DeriveRelativeLocation();
     this.Urn             = DeriveUrn();
     this.LineageSegments = Urn.NonSchemeComponents.Zip(RelativeLocation.Split('/'), (x, y) => (x, y)).ToList();
     this.Segment         = (Urn.ToString(), RelativeLocation.ToString());
 }
 public void String()
 {
     Assert.AreEqual("(0, 0)", loc.ToString());
     Assert.AreEqual("(1234, 987)", loc_1234_987.ToString());
 }