using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IPA.Config.Data
{
///
/// A base value type for config data abstract representations, to be serialized with an
/// . If a is , then
/// that represents just that: a null in whatever serialization is being used.
/// Also contains factory functions for all derived types.
///
public abstract class Value
{
///
/// Converts this into a human-readable format.
///
/// a human-readable string containing the value provided
public abstract override string ToString();
///
/// Creates a Null .
///
///
public static Value Null() => null;
///
/// Creates an empty .
///
/// an empty
///
public static List List() => new List();
///
/// Creates an empty .
///
/// an empty
///
///
public static Map Map() => new Map();
///
/// Creates a new representing a .
///
/// the value to wrap
/// a wrapping
///
public static Text From(string val) => Text(val);
///
/// Creates a new object wrapping a .
///
/// the value to wrap
/// a wrapping
///
public static Text Text(string val) => val == null ? null : new Text { Value = val };
///
/// Creates a new wrapping a .
///
/// the value to wrap
/// a wrapping
///
public static Integer From(long val) => Integer(val);
///
/// Creates a new wrapping a .
///
/// the value to wrap
/// a wrapping
///
public static Integer Integer(long val) => new Integer { Value = val };
///
/// Creates a new wrapping a .
///
/// the value to wrap
/// a wrapping
///
public static FloatingPoint From(decimal val) => Float(val);
///
/// Creates a new wrapping a .
///
/// the value to wrap
/// a wrapping
///
public static FloatingPoint Float(decimal val) => new FloatingPoint { Value = val };
///
/// Creates a new wrapping a .
///
/// the value to wrap
/// a wrapping
///
public static Boolean From(bool val) => Bool(val);
///
/// Creates a new wrapping a .
///
/// the value to wrap
/// a wrapping
///
public static Boolean Bool(bool val) => new Boolean { Value = val };
///
/// Creates a new holding the content of an
/// of .
///
/// the s to initialize the with
/// a containing the content of
///
public static List From(IEnumerable vals)
{
if (vals == null) return null;
var l = List();
l.AddRange(vals);
return l;
}
///
/// Creates a new holding the content of an
/// of to .
///
/// the dictionary of s to initialize the wtih
/// a containing the content of
///
///
public static Map From(IDictionary vals) => From(vals as IEnumerable>);
///
/// Creates a new holding the content of an
/// of of to .
///
/// the enumerable of of name to
/// a containing the content of
///
///
public static Map From(IEnumerable> vals)
{
if (vals == null) return null;
var m = Map();
foreach (var v in vals) m.Add(v.Key, v.Value);
return m;
}
}
}