ln.json/JSONValue.cs

52 lines
1.7 KiB
C#

// /**
// * File: JSONValue.cs
// * Author: haraldwolff
// *
// * This file and it's content is copyrighted by the Author and / or copyright holder.
// * Any use wihtout proper permission is illegal and may lead to legal actions.
// *
// *
// **/
using System;
using System.Collections.Generic;
using ln.json.mapping;
namespace ln.json
{
public enum JSONValueType
{
NULL, OBJECT, ARRAY, STRING, NUMBER, TRUE, FALSE
}
public abstract class JSONValue
{
public JSONValueType ValueType { get; private set; }
public virtual bool HasChildren => false;
public virtual IEnumerable<JSONValue> Children => throw new NotSupportedException();
public virtual object ToNative() => throw new NotImplementedException();
public JSONValue(JSONValueType valueType)
{
ValueType = valueType;
}
public virtual JSONValue this[string property]
{
get => throw new NotSupportedException();
set => throw new NotSupportedException();
}
public virtual JSONValue this[int index]
{
get => throw new NotSupportedException();
set => throw new NotSupportedException();
}
public override string ToString() => throw new NotImplementedException();
public static implicit operator JSONValue(String text) => new JSONString(text);
public static implicit operator JSONValue(bool b) => b ? (JSONValue)JSONTrue.Instance : (JSONValue)JSONFalse.Instance;
public static implicit operator JSONValue(int i) => new JSONNumber(i);
public static implicit operator JSONValue(double d) => new JSONNumber(d);
}
}