示例#1
0
        /// <summary>
        /// Tries to get JTokens ref, id, and type from <paramref name="node"/>. Sets NodeRefId, NodeId, and ServerTypeNameInfo in the returned JsonNodeInfo object
        /// </summary>
        public JsonNodeInfo VisitNode(JObject node, MappingContext mappingContext, NodeContext nodeContext)
        {
            var result = new JsonNodeInfo();

            JToken refToken;

            if (node.TryGetValue("$ref", out refToken))
            {
                result.NodeRefId = refToken.Value <String>();
                return(result);
            }

            JToken idToken;

            if (node.TryGetValue("$id", out idToken))
            {
                result.NodeId = idToken.Value <String>();
            }

            JToken typeToken;

            if (node.TryGetValue("$type", out typeToken))
            {
                var clrTypeName = typeToken.Value <String>();
                result.ServerTypeNameInfo = TypeNameInfo.FromClrTypeName(clrTypeName);
            }

            return(result);
        }
示例#2
0
    public JsonNodeInfo VisitNode(JObject node, MappingContext mappingContext, NodeContext nodeContext) {
      var result = new JsonNodeInfo();
      var idProp = node.Property("id");
      var modelsProp = node.Property("models");
      if (idProp != null && modelsProp != null) {
        node.Add("modelLinks", modelsProp.Value);
        modelsProp.Value = new JArray();
        result.ServerTypeNameInfo = new TypeNameInfo("Make", "");
        return result;
      }

      var makeProp = node.Property("make");
      if (idProp != null && makeProp != null) {
        node.Add("makeLink", makeProp.Value);
        makeProp.Value = null;
        var catsProp = node.Property("categories");
        if (catsProp != null) {
          var styleProps = catsProp["Vehicle Style"];
          var styles = styleProps.Select(t => t.Value<String>()).ToAggregateString(", ");
          node.Add("vehicleStyles", new JValue(styles));
        }
        result.ServerTypeNameInfo = new TypeNameInfo("Model", "");
        return result;
      }
      return result;
      //// Model parser
      //else if (node.id && node.makeId) {
      //    // move 'node.make' link so 'make' can be null reference
      //    node.makeLink = node.make;
      //    node.make = null;

      //    // flatten styles and sizes as comma-separated strings
      //    var styles = node.categories && node.categories["Vehicle Style"];
      //    node.vehicleStyles = styles && styles.join(", ");
      //    var sizes = node.categories && node.categories["Vehicle Size"];
      //    node.vehicleSizes = sizes && sizes.join(", ");

      //    return { entityType: "Model" };
      //}
    }
    public JsonNodeInfo VisitNode(JObject node, MappingContext mappingContext, NodeContext nodeContext) {
      var result = new JsonNodeInfo();

      JToken refToken;
      if (node.TryGetValue("$ref", out refToken)) {
        result.NodeRefId = refToken.Value<String>();
        return result;
      }

      JToken idToken;
      if (node.TryGetValue("$id", out idToken)) {
        result.NodeId = idToken.Value<String>();
      }

      JToken typeToken;
      if (node.TryGetValue("$type", out typeToken)) {
        var clrTypeName = typeToken.Value<String>();
        result.ServerTypeNameInfo = TypeNameInfo.FromClrTypeName(clrTypeName);
      }

      return result;
    }