Exemple #1
0
 public static bool TryParse(
     string json,
     out CosmosObject cosmosObject)
 {
     return(CosmosElement.TryParse <CosmosObject>(json, out cosmosObject));
 }
        public static CosmosElement Dispatch(
            IJsonNavigator jsonNavigator,
            IJsonNavigatorNode jsonNavigatorNode)
        {
            JsonNodeType  jsonNodeType = jsonNavigator.GetNodeType(jsonNavigatorNode);
            CosmosElement item;

            switch (jsonNodeType)
            {
            case JsonNodeType.Null:
                item = CosmosNull.Create();
                break;

            case JsonNodeType.False:
                item = CosmosBoolean.Create(false);
                break;

            case JsonNodeType.True:
                item = CosmosBoolean.Create(true);
                break;

            case JsonNodeType.Number:
                item = CosmosNumber64.Create(jsonNavigator, jsonNavigatorNode);
                break;

            case JsonNodeType.FieldName:
            case JsonNodeType.String:
                item = CosmosString.Create(jsonNavigator, jsonNavigatorNode);
                break;

            case JsonNodeType.Array:
                item = CosmosArray.Create(jsonNavigator, jsonNavigatorNode);
                break;

            case JsonNodeType.Object:
                item = CosmosObject.Create(jsonNavigator, jsonNavigatorNode);
                break;

            case JsonNodeType.Int8:
                item = CosmosInt8.Create(jsonNavigator, jsonNavigatorNode);
                break;

            case JsonNodeType.Int16:
                item = CosmosInt16.Create(jsonNavigator, jsonNavigatorNode);
                break;

            case JsonNodeType.Int32:
                item = CosmosInt32.Create(jsonNavigator, jsonNavigatorNode);
                break;

            case JsonNodeType.Int64:
                item = CosmosInt64.Create(jsonNavigator, jsonNavigatorNode);
                break;

            case JsonNodeType.UInt32:
                item = CosmosUInt32.Create(jsonNavigator, jsonNavigatorNode);
                break;

            case JsonNodeType.Float32:
                item = CosmosFloat32.Create(jsonNavigator, jsonNavigatorNode);
                break;

            case JsonNodeType.Float64:
                item = CosmosFloat64.Create(jsonNavigator, jsonNavigatorNode);
                break;

            case JsonNodeType.Guid:
                item = CosmosGuid.Create(jsonNavigator, jsonNavigatorNode);
                break;

            case JsonNodeType.Binary:
                item = CosmosBinary.Create(jsonNavigator, jsonNavigatorNode);
                break;

            default:
                throw new ArgumentException($"Unknown {nameof(JsonNodeType)}: {jsonNodeType}");
            }

            return(item);
        }
Exemple #3
0
 public static bool TryCreateFromBuffer(
     ReadOnlyMemory <byte> buffer,
     out CosmosObject cosmosObject)
 {
     return(CosmosElement.TryCreateFromBuffer <CosmosObject>(buffer, out cosmosObject));
 }