Ejemplo n.º 1
0
        public bool TryRead <TValue>(out TValue value, params string[] path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            var filename = Path.Combine(DataPath, Path.Combine(path));

            if (!filename.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
            {
                filename += ".json";
            }

            if (!File.Exists(filename))
            {
                value = default(TValue);
                return(false);
            }

            var json = File.ReadAllText(filename, Encoding.UTF8);

            if (string.IsNullOrEmpty(json))
            {
                value = default(TValue);
                return(true);
            }

            value = _jsonSerializerService.Deserialize <TValue>(json);
            return(true);
        }
Ejemplo n.º 2
0
        public bool TryReadSerializedValue <TValue>(out TValue value, params string[] path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            var filename = Path.Combine(path);

            if (!filename.EndsWith(JsonExtension, StringComparison.Ordinal))
            {
                filename += JsonExtension;
            }

            if (!TryReadRawText(out var textValue, filename))
            {
                value = default;
                return(false);
            }

            value = _jsonSerializerService.Deserialize <TValue>(textValue);
            return(true);
        }