Exemplo n.º 1
0
        private static bool TryConvert(Type type, LooseObject obj, out object output)
        {
            if (type == typeof(int)) {
                output = (int) obj.ToNumber();
                return true;
            }

            if (type == typeof(float)) {
                output = obj.ToNumber();
                return true;
            }

            if (type == typeof(string)) {
                output = obj.ToString();
                return true;
            }

            if (typeof(LooseObject).IsAssignableFrom(type)) {
                output = obj;
                return true;
            }

            output = null;
            return false;
        }
        public static string Serialize(LooseObject obj)
        {
            StringBuilder str = new StringBuilder();

            SerializeObject(str, obj);

            return str.ToString();
        }
 private static void SerializeObject(StringBuilder str, LooseObject obj)
 {
     if (obj == null)
         str.Append("null");
     else if (obj is LooseDictionary)
         SerializeDictionary(str, (LooseDictionary) obj);
     else if (obj is LooseArray)
         SerializeArray(str, (LooseArray) obj);
     else if (obj is LooseString)
         SerializeString(str, (LooseString) obj);
     else if (obj is LooseNumber)
         str.Append(((LooseNumber) obj).Number.ToString());
 }
 public bool TryGetValue(string key, out LooseObject obj)
 {
     return(this.dictionary.TryGetValue(key, out obj));
 }
 public void Add(string key, LooseObject value)
 {
     this.dictionary.Add(key, value);
 }
 public void Add(string key, LooseObject value)
 {
     this.dictionary.Add(key, value);
 }
 public bool TryGetValue(string key, out LooseObject obj)
 {
     return this.dictionary.TryGetValue(key, out obj);
 }