0312 更新ExecuteAlways 升级litjson
| | |
| | | public ICollection<string> Keys { |
| | | get { EnsureDictionary (); return inst_object.Keys; } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Determines whether the json contains an element that has the specified key. |
| | | /// </summary> |
| | | /// <param name="key">The key to locate in the json.</param> |
| | | /// <returns>true if the json contains an element that has the specified key; otherwise, false.</returns> |
| | | public Boolean ContainsKey(String key) { |
| | | EnsureDictionary(); |
| | | return this.inst_object.Keys.Contains(key); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | |
| | | |
| | | public static explicit operator Int32 (JsonData data) |
| | | { |
| | | if (data.type != JsonType.Int) |
| | | if (data.type != JsonType.Int && data.type != JsonType.Long) |
| | | { |
| | | throw new InvalidCastException ( |
| | | "Instance of JsonData doesn't hold an int"); |
| | | } |
| | | |
| | | return data.inst_int; |
| | | // cast may truncate data... but that's up to the user to consider |
| | | return data.type == JsonType.Int ? data.inst_int : (int)data.inst_long; |
| | | } |
| | | |
| | | public static explicit operator Int64 (JsonData data) |
| | | { |
| | | if (data.type != JsonType.Long) |
| | | if (data.type != JsonType.Long && data.type != JsonType.Int) |
| | | { |
| | | throw new InvalidCastException ( |
| | | "Instance of JsonData doesn't hold an int"); |
| | | "Instance of JsonData doesn't hold a long"); |
| | | } |
| | | |
| | | return data.inst_long; |
| | | return data.type == JsonType.Long ? data.inst_long : data.inst_int; |
| | | } |
| | | |
| | | public static explicit operator String (JsonData data) |
| | |
| | | return EnsureList ().Add (data); |
| | | } |
| | | |
| | | public bool Remove(object obj) |
| | | { |
| | | json = null; |
| | | if(IsObject) |
| | | { |
| | | JsonData value = null; |
| | | if (inst_object.TryGetValue((string)obj, out value)) |
| | | return inst_object.Remove((string)obj) && object_list.Remove(new KeyValuePair<string, JsonData>((string)obj, value)); |
| | | else |
| | | throw new KeyNotFoundException("The specified key was not found in the JsonData object."); |
| | | } |
| | | if(IsArray) |
| | | { |
| | | return inst_array.Remove(ToJsonData(obj)); |
| | | } |
| | | throw new InvalidOperationException ( |
| | | "Instance of JsonData is not an object or a list."); |
| | | } |
| | | |
| | | public void Clear () |
| | | { |
| | | if (IsObject) { |
| | |
| | | return false; |
| | | |
| | | if (x.type != this.type) |
| | | { |
| | | // further check to see if this is a long to int comparison |
| | | if ((x.type != JsonType.Int && x.type != JsonType.Long) |
| | | || (this.type != JsonType.Int && this.type != JsonType.Long)) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | switch (this.type) { |
| | | case JsonType.None: |
| | |
| | | return this.inst_string.Equals (x.inst_string); |
| | | |
| | | case JsonType.Int: |
| | | { |
| | | if (x.IsLong) |
| | | { |
| | | if (x.inst_long < Int32.MinValue || x.inst_long > Int32.MaxValue) |
| | | return false; |
| | | return this.inst_int.Equals((int)x.inst_long); |
| | | } |
| | | return this.inst_int.Equals (x.inst_int); |
| | | } |
| | | |
| | | case JsonType.Long: |
| | | { |
| | | if (x.IsInt) |
| | | { |
| | | if (this.inst_long < Int32.MinValue || this.inst_long > Int32.MaxValue) |
| | | return false; |
| | | return x.inst_int.Equals((int)this.inst_long); |
| | | } |
| | | return this.inst_long.Equals (x.inst_long); |
| | | } |
| | | |
| | | case JsonType.Double: |
| | | return this.inst_double.Equals (x.inst_double); |
| | |
| | | |
| | | namespace LitJson |
| | | { |
| | | public class JsonException : ApplicationException |
| | | public class JsonException : |
| | | #if NETSTANDARD1_5 |
| | | Exception |
| | | #else |
| | | ApplicationException |
| | | #endif |
| | | { |
| | | public JsonException () : base () |
| | | { |
| | |
| | | using System.Reflection; |
| | | |
| | | |
| | | namespace LitJson { |
| | | internal struct PropertyMetadata { |
| | | namespace LitJson |
| | | { |
| | | internal struct PropertyMetadata |
| | | { |
| | | public MemberInfo Info; |
| | | public bool IsField; |
| | | public Type Type; |
| | | } |
| | | |
| | | |
| | | internal struct ArrayMetadata { |
| | | internal struct ArrayMetadata |
| | | { |
| | | private Type element_type; |
| | | private bool is_array; |
| | | private bool is_list; |
| | |
| | | } |
| | | |
| | | |
| | | internal struct ObjectMetadata { |
| | | internal struct ObjectMetadata |
| | | { |
| | | private Type element_type; |
| | | private bool is_dictionary; |
| | | |
| | |
| | | public delegate IJsonWrapper WrapperFactory (); |
| | | |
| | | |
| | | public class JsonMapper { |
| | | public class JsonMapper |
| | | { |
| | | #region Fields |
| | | private static int max_nesting_depth; |
| | | private static readonly int max_nesting_depth; |
| | | |
| | | private static IFormatProvider datetime_format; |
| | | private static readonly IFormatProvider datetime_format; |
| | | |
| | | private static IDictionary<Type, ExporterFunc> base_exporters_table; |
| | | private static IDictionary<Type, ExporterFunc> custom_exporters_table; |
| | | private static readonly IDictionary<Type, ExporterFunc> base_exporters_table; |
| | | private static readonly IDictionary<Type, ExporterFunc> custom_exporters_table; |
| | | |
| | | private static IDictionary<Type, |
| | | private static readonly IDictionary<Type, |
| | | IDictionary<Type, ImporterFunc>> base_importers_table; |
| | | private static IDictionary<Type, |
| | | private static readonly IDictionary<Type, |
| | | IDictionary<Type, ImporterFunc>> custom_importers_table; |
| | | |
| | | private static IDictionary<Type, ArrayMetadata> array_metadata; |
| | | private static readonly IDictionary<Type, ArrayMetadata> array_metadata; |
| | | private static readonly object array_metadata_lock = new Object(); |
| | | |
| | | private static IDictionary<Type, |
| | | private static readonly IDictionary<Type, |
| | | IDictionary<Type, MethodInfo>> conv_ops; |
| | | private static readonly object conv_ops_lock = new Object(); |
| | | |
| | | private static IDictionary<Type, ObjectMetadata> object_metadata; |
| | | private static readonly IDictionary<Type, ObjectMetadata> object_metadata; |
| | | private static readonly object object_metadata_lock = new Object(); |
| | | |
| | | private static IDictionary<Type, |
| | | private static readonly IDictionary<Type, |
| | | IList<PropertyMetadata>> type_properties; |
| | | private static readonly object type_properties_lock = new Object(); |
| | | |
| | | private static JsonWriter static_writer; |
| | | private static readonly JsonWriter static_writer; |
| | | private static readonly object static_writer_lock = new Object(); |
| | | #endregion |
| | | |
| | | |
| | | #region Constructors |
| | | static JsonMapper () { |
| | | static JsonMapper () |
| | | { |
| | | max_nesting_depth = 100; |
| | | |
| | | array_metadata = new Dictionary<Type, ArrayMetadata>(); |
| | |
| | | |
| | | |
| | | #region Private Methods |
| | | private static void AddArrayMetadata (Type type) { |
| | | private static void AddArrayMetadata (Type type) |
| | | { |
| | | if (array_metadata.ContainsKey(type)) |
| | | return; |
| | | |
| | |
| | | lock (array_metadata_lock) { |
| | | try { |
| | | array_metadata.Add(type, data); |
| | | } |
| | | catch (ArgumentException) { |
| | | } catch (ArgumentException) { |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private static void AddObjectMetadata (Type type) { |
| | | private static void AddObjectMetadata (Type type) |
| | | { |
| | | if (object_metadata.ContainsKey(type)) |
| | | return; |
| | | |
| | |
| | | data.Properties.Add(p_info.Name, p_data); |
| | | } |
| | | |
| | | foreach (FieldInfo f_info in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)) { |
| | | if (f_info.IsNotSerialized) |
| | | continue; |
| | | foreach (FieldInfo f_info in type.GetFields ()) { |
| | | PropertyMetadata p_data = new PropertyMetadata(); |
| | | p_data.Info = f_info; |
| | | p_data.IsField = true; |
| | |
| | | lock (object_metadata_lock) { |
| | | try { |
| | | object_metadata.Add(type, data); |
| | | } |
| | | catch (ArgumentException) { |
| | | } catch (ArgumentException) { |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private static void AddTypeProperties (Type type) { |
| | | private static void AddTypeProperties (Type type) |
| | | { |
| | | if (type_properties.ContainsKey(type)) |
| | | return; |
| | | |
| | |
| | | foreach (PropertyInfo p_info in type.GetProperties()) { |
| | | if (p_info.Name == "Item") |
| | | continue; |
| | | |
| | | PropertyMetadata p_data = new PropertyMetadata(); |
| | | p_data.Info = p_info; |
| | | p_data.IsField = false; |
| | | props.Add(p_data); |
| | | } |
| | | |
| | | foreach (FieldInfo f_info in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)) { |
| | | if (f_info.IsNotSerialized) |
| | | continue; |
| | | foreach (FieldInfo f_info in type.GetFields ()) { |
| | | PropertyMetadata p_data = new PropertyMetadata(); |
| | | p_data.Info = f_info; |
| | | p_data.IsField = true; |
| | |
| | | lock (type_properties_lock) { |
| | | try { |
| | | type_properties.Add(type, props); |
| | | } |
| | | catch (ArgumentException) { |
| | | } catch (ArgumentException) { |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private static MethodInfo GetConvOp (Type t1, Type t2) { |
| | | private static MethodInfo GetConvOp (Type t1, Type t2) |
| | | { |
| | | lock (conv_ops_lock) { |
| | | if (!conv_ops.ContainsKey(t1)) |
| | | conv_ops.Add(t1, new Dictionary<Type, MethodInfo>()); |
| | |
| | | lock (conv_ops_lock) { |
| | | try { |
| | | conv_ops[t1].Add(t2, op); |
| | | } |
| | | catch (ArgumentException) { |
| | | } catch (ArgumentException) { |
| | | return conv_ops[t1][t2]; |
| | | } |
| | | } |
| | |
| | | return op; |
| | | } |
| | | |
| | | private static object ReadValue (Type inst_type, JsonReader reader) { |
| | | private static object ReadValue (Type inst_type, JsonReader reader) |
| | | { |
| | | reader.Read(); |
| | | |
| | | if (reader.Token == JsonToken.ArrayEnd) |
| | |
| | | Type value_type = underlying_type ?? inst_type; |
| | | |
| | | if (reader.Token == JsonToken.Null) { |
| | | #if NETSTANDARD1_5 |
| | | if (inst_type.IsClass() || underlying_type != null) { |
| | | return null; |
| | | } |
| | | #else |
| | | if (inst_type.IsClass || underlying_type != null) { |
| | | return null; |
| | | } |
| | | #endif |
| | | |
| | | throw new JsonException(String.Format( |
| | | "Can't assign null to an instance of type {0}", |
| | |
| | | } |
| | | |
| | | // Maybe it's an enum |
| | | #if NETSTANDARD1_5 |
| | | if (value_type.IsEnum()) |
| | | return Enum.ToObject (value_type, reader.Value); |
| | | #else |
| | | if (value_type.IsEnum) |
| | | return Enum.ToObject(value_type, reader.Value); |
| | | |
| | | #endif |
| | | // Try using an implicit conversion operator |
| | | MethodInfo conv_op = GetConvOp(value_type, json_type); |
| | | |
| | |
| | | if (!t_data.IsArray) { |
| | | list = (IList)Activator.CreateInstance(inst_type); |
| | | elem_type = t_data.ElementType; |
| | | } |
| | | else { |
| | | } else { |
| | | list = new ArrayList(); |
| | | elem_type = inst_type.GetElementType(); |
| | | } |
| | | |
| | | list.Clear(); |
| | | |
| | | while (true) { |
| | | object item = ReadValue(elem_type, reader); |
| | |
| | | |
| | | for (int i = 0; i < n; i++) |
| | | ((Array)instance).SetValue(list[i], i); |
| | | } |
| | | else |
| | | } else |
| | | instance = list; |
| | | |
| | | } |
| | | else if (reader.Token == JsonToken.ObjectStart) { |
| | | } else if (reader.Token == JsonToken.ObjectStart) { |
| | | AddObjectMetadata(value_type); |
| | | ObjectMetadata t_data = object_metadata[value_type]; |
| | | |
| | |
| | | if (prop_data.IsField) { |
| | | ((FieldInfo)prop_data.Info).SetValue( |
| | | instance, ReadValue(prop_data.Type, reader)); |
| | | } |
| | | else { |
| | | } else { |
| | | PropertyInfo p_info = |
| | | (PropertyInfo)prop_data.Info; |
| | | |
| | |
| | | ReadValue(prop_data.Type, reader); |
| | | } |
| | | |
| | | } |
| | | else { |
| | | } else { |
| | | if (!t_data.IsDictionary) { |
| | | |
| | | if (!reader.SkipNonMembers) { |
| | |
| | | "The type {0} doesn't have the " + |
| | | "property '{1}'", |
| | | inst_type, property)); |
| | | } |
| | | else { |
| | | } else { |
| | | ReadSkip(reader); |
| | | continue; |
| | | } |
| | |
| | | } |
| | | |
| | | private static IJsonWrapper ReadValue (WrapperFactory factory, |
| | | JsonReader reader) { |
| | | JsonReader reader) |
| | | { |
| | | reader.Read(); |
| | | |
| | | if (reader.Token == JsonToken.ArrayEnd || |
| | |
| | | return instance; |
| | | } |
| | | |
| | | private static void ReadSkip (JsonReader reader) { |
| | | private static void ReadSkip (JsonReader reader) |
| | | { |
| | | ToWrapper( |
| | | delegate { return new JsonMockWrapper(); }, reader); |
| | | } |
| | | |
| | | private static void RegisterBaseExporters () { |
| | | private static void RegisterBaseExporters () |
| | | { |
| | | base_exporters_table[typeof(byte)] = |
| | | delegate (object obj, JsonWriter writer) { |
| | | writer.Write(Convert.ToInt32((byte)obj)); |
| | |
| | | delegate (object obj, JsonWriter writer) { |
| | | writer.Write((ulong)obj); |
| | | }; |
| | | |
| | | base_exporters_table[typeof(DateTimeOffset)] = |
| | | delegate (object obj, JsonWriter writer) { |
| | | writer.Write(((DateTimeOffset)obj).ToString("yyyy-MM-ddTHH:mm:ss.fffffffzzz", datetime_format)); |
| | | }; |
| | | } |
| | | |
| | | private static void RegisterBaseImporters () { |
| | | private static void RegisterBaseImporters () |
| | | { |
| | | ImporterFunc importer; |
| | | |
| | | importer = delegate (object input) { |
| | |
| | | }; |
| | | RegisterImporter(base_importers_table, typeof(int), |
| | | typeof(ulong), importer); |
| | | |
| | | importer = delegate (object input) { |
| | | return Convert.ToInt64((int)input); |
| | | }; |
| | | RegisterImporter(base_importers_table, typeof(int), |
| | | typeof(long), importer); |
| | | |
| | | importer = delegate (object input) { |
| | | return Convert.ToSByte((int)input); |
| | |
| | | }; |
| | | RegisterImporter(base_importers_table, typeof(string), |
| | | typeof(DateTime), importer); |
| | | |
| | | importer = delegate (object input) { |
| | | return DateTimeOffset.Parse((string)input, datetime_format); |
| | | }; |
| | | RegisterImporter(base_importers_table, typeof(string), |
| | | typeof(DateTimeOffset), importer); |
| | | } |
| | | |
| | | private static void RegisterImporter ( |
| | | IDictionary<Type, IDictionary<Type, ImporterFunc>> table, |
| | | Type json_type, Type value_type, ImporterFunc importer) { |
| | | Type json_type, Type value_type, ImporterFunc importer) |
| | | { |
| | | if (!table.ContainsKey(json_type)) |
| | | table.Add(json_type, new Dictionary<Type, ImporterFunc>()); |
| | | |
| | |
| | | |
| | | private static void WriteValue (object obj, JsonWriter writer, |
| | | bool writer_is_private, |
| | | int depth) { |
| | | int depth) |
| | | { |
| | | if (depth > max_nesting_depth) |
| | | throw new JsonException(String.Format( |
| | | "Max allowed object depth reached while " + |
| | | throw new JsonException ( |
| | | String.Format ("Max allowed object depth reached while " + |
| | | "trying to export from type {0}", |
| | | obj.GetType())); |
| | | |
| | |
| | | return; |
| | | } |
| | | |
| | | if (obj is IDictionary) { |
| | | if (obj is IDictionary dictionary) { |
| | | writer.WriteObjectStart(); |
| | | foreach (DictionaryEntry entry in (IDictionary)obj) { |
| | | writer.WritePropertyName((string)entry.Key); |
| | | foreach (DictionaryEntry entry in dictionary) { |
| | | var propertyName = entry.Key is string key ? |
| | | key |
| | | : Convert.ToString(entry.Key, CultureInfo.InvariantCulture); |
| | | writer.WritePropertyName (propertyName); |
| | | WriteValue(entry.Value, writer, writer_is_private, |
| | | depth + 1); |
| | | } |
| | |
| | | #endregion |
| | | |
| | | |
| | | public static string ToJson (object obj) { |
| | | public static string ToJson (object obj) |
| | | { |
| | | lock (static_writer_lock) { |
| | | static_writer.Reset(); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | public static void ToJson (object obj, JsonWriter writer) { |
| | | public static void ToJson (object obj, JsonWriter writer) |
| | | { |
| | | WriteValue(obj, writer, false, 0); |
| | | } |
| | | |
| | | public static JsonData ToObject (JsonReader reader) { |
| | | public static JsonData ToObject (JsonReader reader) |
| | | { |
| | | return (JsonData)ToWrapper( |
| | | delegate { return new JsonData(); }, reader); |
| | | } |
| | | |
| | | public static JsonData ToObject (TextReader reader) { |
| | | public static JsonData ToObject (TextReader reader) |
| | | { |
| | | JsonReader json_reader = new JsonReader(reader); |
| | | |
| | | return (JsonData)ToWrapper( |
| | | delegate { return new JsonData(); }, json_reader); |
| | | } |
| | | |
| | | public static JsonData ToObject (string json) { |
| | | public static JsonData ToObject (string json) |
| | | { |
| | | return (JsonData)ToWrapper( |
| | | delegate { return new JsonData(); }, json); |
| | | } |
| | | |
| | | public static T ToObject<T> (JsonReader reader) { |
| | | public static T ToObject<T> (JsonReader reader) |
| | | { |
| | | return (T)ReadValue(typeof(T), reader); |
| | | } |
| | | |
| | | public static T ToObject<T> (TextReader reader) { |
| | | public static T ToObject<T> (TextReader reader) |
| | | { |
| | | JsonReader json_reader = new JsonReader(reader); |
| | | |
| | | return (T)ReadValue(typeof(T), json_reader); |
| | | } |
| | | |
| | | public static T ToObject<T> (string json) { |
| | | public static T ToObject<T> (string json) |
| | | { |
| | | JsonReader reader = new JsonReader(json); |
| | | |
| | | return (T)ReadValue(typeof(T), reader); |
| | | } |
| | | |
| | | public static object ToObject(string json, Type ConvertType ) |
| | | { |
| | | JsonReader reader = new JsonReader(json); |
| | | |
| | | return ReadValue(ConvertType, reader); |
| | | } |
| | | |
| | | public static IJsonWrapper ToWrapper (WrapperFactory factory, |
| | | JsonReader reader) { |
| | | JsonReader reader) |
| | | { |
| | | return ReadValue(factory, reader); |
| | | } |
| | | |
| | | public static IJsonWrapper ToWrapper (WrapperFactory factory, |
| | | string json) { |
| | | string json) |
| | | { |
| | | JsonReader reader = new JsonReader(json); |
| | | |
| | | return ReadValue(factory, reader); |
| | | } |
| | | |
| | | public static void RegisterExporter<T> (ExporterFunc<T> exporter) { |
| | | public static void RegisterExporter<T> (ExporterFunc<T> exporter) |
| | | { |
| | | ExporterFunc exporter_wrapper = |
| | | delegate (object obj, JsonWriter writer) { |
| | | exporter((T)obj, writer); |
| | |
| | | } |
| | | |
| | | public static void RegisterImporter<TJson, TValue> ( |
| | | ImporterFunc<TJson, TValue> importer) { |
| | | ImporterFunc<TJson, TValue> importer) |
| | | { |
| | | ImporterFunc importer_wrapper = |
| | | delegate (object input) { |
| | | return importer((TJson)input); |
| | |
| | | typeof(TValue), importer_wrapper); |
| | | } |
| | | |
| | | public static void UnregisterExporters () { |
| | | public static void UnregisterExporters () |
| | | { |
| | | custom_exporters_table.Clear(); |
| | | } |
| | | |
| | | public static void UnregisterImporters () { |
| | | public static void UnregisterImporters () |
| | | { |
| | | custom_importers_table.Clear(); |
| | | } |
| | | } |
| | |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Globalization; |
| | | using System.IO; |
| | | using System.Text; |
| | | |
| | |
| | | public class JsonReader |
| | | { |
| | | #region Fields |
| | | private static IDictionary<int, IDictionary<int, int[]>> parse_table; |
| | | private static readonly IDictionary<int, IDictionary<int, int[]>> parse_table; |
| | | |
| | | private Stack<int> automaton_stack; |
| | | private int current_input; |
| | |
| | | #region Constructors |
| | | static JsonReader () |
| | | { |
| | | PopulateParseTable (); |
| | | parse_table = PopulateParseTable (); |
| | | } |
| | | |
| | | public JsonReader (string json_text) : |
| | |
| | | |
| | | |
| | | #region Static Methods |
| | | private static void PopulateParseTable () |
| | | private static IDictionary<int, IDictionary<int, int[]>> PopulateParseTable () |
| | | { |
| | | // See section A.2. of the manual for details |
| | | parse_table = new Dictionary<int, IDictionary<int, int[]>> (); |
| | | IDictionary<int, IDictionary<int, int[]>> parse_table = new Dictionary<int, IDictionary<int, int[]>> (); |
| | | |
| | | TableAddRow (ParserToken.Array); |
| | | TableAddCol (ParserToken.Array, '[', |
| | | TableAddRow (parse_table, ParserToken.Array); |
| | | TableAddCol (parse_table, ParserToken.Array, '[', |
| | | '[', |
| | | (int) ParserToken.ArrayPrime); |
| | | |
| | | TableAddRow (ParserToken.ArrayPrime); |
| | | TableAddCol (ParserToken.ArrayPrime, '"', |
| | | TableAddRow (parse_table, ParserToken.ArrayPrime); |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, '"', |
| | | (int) ParserToken.Value, |
| | | |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, '[', |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, '[', |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, ']', |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, ']', |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, '{', |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, '{', |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, (int) ParserToken.Number, |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.Number, |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, (int) ParserToken.True, |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.True, |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, (int) ParserToken.False, |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.False, |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, (int) ParserToken.Null, |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.Null, |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | |
| | | TableAddRow (ParserToken.Object); |
| | | TableAddCol (ParserToken.Object, '{', |
| | | TableAddRow (parse_table, ParserToken.Object); |
| | | TableAddCol (parse_table, ParserToken.Object, '{', |
| | | '{', |
| | | (int) ParserToken.ObjectPrime); |
| | | |
| | | TableAddRow (ParserToken.ObjectPrime); |
| | | TableAddCol (ParserToken.ObjectPrime, '"', |
| | | TableAddRow (parse_table, ParserToken.ObjectPrime); |
| | | TableAddCol (parse_table, ParserToken.ObjectPrime, '"', |
| | | (int) ParserToken.Pair, |
| | | (int) ParserToken.PairRest, |
| | | '}'); |
| | | TableAddCol (ParserToken.ObjectPrime, '}', |
| | | TableAddCol (parse_table, ParserToken.ObjectPrime, '}', |
| | | '}'); |
| | | |
| | | TableAddRow (ParserToken.Pair); |
| | | TableAddCol (ParserToken.Pair, '"', |
| | | TableAddRow (parse_table, ParserToken.Pair); |
| | | TableAddCol (parse_table, ParserToken.Pair, '"', |
| | | (int) ParserToken.String, |
| | | ':', |
| | | (int) ParserToken.Value); |
| | | |
| | | TableAddRow (ParserToken.PairRest); |
| | | TableAddCol (ParserToken.PairRest, ',', |
| | | TableAddRow (parse_table, ParserToken.PairRest); |
| | | TableAddCol (parse_table, ParserToken.PairRest, ',', |
| | | ',', |
| | | (int) ParserToken.Pair, |
| | | (int) ParserToken.PairRest); |
| | | TableAddCol (ParserToken.PairRest, '}', |
| | | TableAddCol (parse_table, ParserToken.PairRest, '}', |
| | | (int) ParserToken.Epsilon); |
| | | |
| | | TableAddRow (ParserToken.String); |
| | | TableAddCol (ParserToken.String, '"', |
| | | TableAddRow (parse_table, ParserToken.String); |
| | | TableAddCol (parse_table, ParserToken.String, '"', |
| | | '"', |
| | | (int) ParserToken.CharSeq, |
| | | '"'); |
| | | |
| | | TableAddRow (ParserToken.Text); |
| | | TableAddCol (ParserToken.Text, '[', |
| | | TableAddRow (parse_table, ParserToken.Text); |
| | | TableAddCol (parse_table, ParserToken.Text, '[', |
| | | (int) ParserToken.Array); |
| | | TableAddCol (ParserToken.Text, '{', |
| | | TableAddCol (parse_table, ParserToken.Text, '{', |
| | | (int) ParserToken.Object); |
| | | |
| | | TableAddRow (ParserToken.Value); |
| | | TableAddCol (ParserToken.Value, '"', |
| | | TableAddRow (parse_table, ParserToken.Value); |
| | | TableAddCol (parse_table, ParserToken.Value, '"', |
| | | (int) ParserToken.String); |
| | | TableAddCol (ParserToken.Value, '[', |
| | | TableAddCol (parse_table, ParserToken.Value, '[', |
| | | (int) ParserToken.Array); |
| | | TableAddCol (ParserToken.Value, '{', |
| | | TableAddCol (parse_table, ParserToken.Value, '{', |
| | | (int) ParserToken.Object); |
| | | TableAddCol (ParserToken.Value, (int) ParserToken.Number, |
| | | TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.Number, |
| | | (int) ParserToken.Number); |
| | | TableAddCol (ParserToken.Value, (int) ParserToken.True, |
| | | TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.True, |
| | | (int) ParserToken.True); |
| | | TableAddCol (ParserToken.Value, (int) ParserToken.False, |
| | | TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.False, |
| | | (int) ParserToken.False); |
| | | TableAddCol (ParserToken.Value, (int) ParserToken.Null, |
| | | TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.Null, |
| | | (int) ParserToken.Null); |
| | | |
| | | TableAddRow (ParserToken.ValueRest); |
| | | TableAddCol (ParserToken.ValueRest, ',', |
| | | TableAddRow (parse_table, ParserToken.ValueRest); |
| | | TableAddCol (parse_table, ParserToken.ValueRest, ',', |
| | | ',', |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest); |
| | | TableAddCol (ParserToken.ValueRest, ']', |
| | | TableAddCol (parse_table, ParserToken.ValueRest, ']', |
| | | (int) ParserToken.Epsilon); |
| | | |
| | | return parse_table; |
| | | } |
| | | |
| | | private static void TableAddCol (ParserToken row, int col, |
| | | private static void TableAddCol (IDictionary<int, IDictionary<int, int[]>> parse_table, ParserToken row, int col, |
| | | params int[] symbols) |
| | | { |
| | | parse_table[(int) row].Add (col, symbols); |
| | | } |
| | | |
| | | private static void TableAddRow (ParserToken rule) |
| | | private static void TableAddRow (IDictionary<int, IDictionary<int, int[]>> parse_table, ParserToken rule) |
| | | { |
| | | parse_table.Add ((int) rule, new Dictionary<int, int[]> ()); |
| | | } |
| | |
| | | number.IndexOf ('E') != -1) { |
| | | |
| | | double n_double; |
| | | if (Double.TryParse (number, out n_double)) { |
| | | if (double.TryParse (number, NumberStyles.Any, CultureInfo.InvariantCulture, out n_double)) { |
| | | token = JsonToken.Double; |
| | | token_value = n_double; |
| | | |
| | |
| | | } |
| | | |
| | | int n_int32; |
| | | if (Int32.TryParse (number, out n_int32)) { |
| | | if (int.TryParse (number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_int32)) { |
| | | token = JsonToken.Int; |
| | | token_value = n_int32; |
| | | |
| | |
| | | } |
| | | |
| | | long n_int64; |
| | | if (Int64.TryParse (number, out n_int64)) { |
| | | if (long.TryParse (number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_int64)) { |
| | | token = JsonToken.Long; |
| | | token_value = n_int64; |
| | | |
| | |
| | | } |
| | | |
| | | ulong n_uint64; |
| | | if (UInt64.TryParse(number, out n_uint64)) |
| | | if (ulong.TryParse(number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_uint64)) |
| | | { |
| | | token = JsonToken.Long; |
| | | token_value = n_uint64; |
| | |
| | | end_of_json = true; |
| | | |
| | | if (reader_is_owned) |
| | | reader.Close (); |
| | | { |
| | | using(reader){} |
| | | } |
| | | |
| | | reader = null; |
| | | } |
| | |
| | | public class JsonWriter |
| | | { |
| | | #region Fields |
| | | private static NumberFormatInfo number_format; |
| | | private static readonly NumberFormatInfo number_format; |
| | | |
| | | private WriterContext context; |
| | | private Stack<WriterContext> ctx_stack; |
| | |
| | | private StringBuilder inst_string_builder; |
| | | private bool pretty_print; |
| | | private bool validate; |
| | | private bool lower_case_properties; |
| | | private TextWriter writer; |
| | | #endregion |
| | | |
| | |
| | | public bool Validate { |
| | | get { return validate; } |
| | | set { validate = value; } |
| | | } |
| | | |
| | | public bool LowerCaseProperties { |
| | | get { return lower_case_properties; } |
| | | set { lower_case_properties = value; } |
| | | } |
| | | #endregion |
| | | |
| | |
| | | indent_value = 4; |
| | | pretty_print = false; |
| | | validate = true; |
| | | lower_case_properties = false; |
| | | |
| | | ctx_stack = new Stack<WriterContext> (); |
| | | context = new WriterContext (); |
| | |
| | | writer.Write (','); |
| | | |
| | | if (pretty_print && ! context.ExpectingValue) |
| | | writer.Write ('\n'); |
| | | writer.Write (Environment.NewLine); |
| | | } |
| | | |
| | | private void PutString (string str) |
| | |
| | | context.ExpectingValue = false; |
| | | } |
| | | |
| | | [CLSCompliant(false)] |
| | | public void Write (ulong number) |
| | | { |
| | | DoValidation (Condition.Value); |
| | |
| | | { |
| | | DoValidation (Condition.Property); |
| | | PutNewline (); |
| | | string propertyName = (property_name == null || !lower_case_properties) |
| | | ? property_name |
| | | : property_name.ToLowerInvariant(); |
| | | |
| | | PutString (property_name); |
| | | PutString (propertyName); |
| | | |
| | | if (pretty_print) { |
| | | if (property_name.Length > context.Padding) |
| | | context.Padding = property_name.Length; |
| | | if (propertyName.Length > context.Padding) |
| | | context.Padding = propertyName.Length; |
| | | |
| | | for (int i = context.Padding - property_name.Length; |
| | | for (int i = context.Padding - propertyName.Length; |
| | | i >= 0; i--) |
| | | writer.Write (' '); |
| | | |
| | |
| | | #region Fields |
| | | private delegate bool StateHandler (FsmContext ctx); |
| | | |
| | | private static int[] fsm_return_table; |
| | | private static StateHandler[] fsm_handler_table; |
| | | private static readonly int[] fsm_return_table; |
| | | private static readonly StateHandler[] fsm_handler_table; |
| | | |
| | | private bool allow_comments; |
| | | private bool allow_single_quoted_strings; |
| | |
| | | #region Constructors |
| | | static Lexer () |
| | | { |
| | | PopulateFsmTables (); |
| | | PopulateFsmTables (out fsm_handler_table, out fsm_return_table); |
| | | } |
| | | |
| | | public Lexer (TextReader reader) |
| | |
| | | } |
| | | } |
| | | |
| | | private static void PopulateFsmTables () |
| | | private static void PopulateFsmTables (out StateHandler[] fsm_handler_table, out int[] fsm_return_table) |
| | | { |
| | | // See section A.1. of the manual for details of the finite |
| | | // state machine. |
New file |
| | |
| | | #if NETSTANDARD1_5 |
| | | using System; |
| | | using System.Reflection; |
| | | namespace LitJson |
| | | { |
| | | internal static class Netstandard15Polyfill |
| | | { |
| | | internal static Type GetInterface(this Type type, string name) |
| | | { |
| | | return type.GetTypeInfo().GetInterface(name); |
| | | } |
| | | |
| | | internal static bool IsClass(this Type type) |
| | | { |
| | | return type.GetTypeInfo().IsClass; |
| | | } |
| | | |
| | | internal static bool IsEnum(this Type type) |
| | | { |
| | | return type.GetTypeInfo().IsEnum; |
| | | } |
| | | } |
| | | } |
| | | #endif |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 155770190c61cbb4dbbde393aec4c23e |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
| | |
| | | |
| | | namespace qtools.qhierarchy |
| | | { |
| | | [ExecuteInEditMode] |
| | | [ExecuteAlways] |
| | | [AddComponentMenu("")] |
| | | public class QObjectList: MonoBehaviour, ISerializationCallbackReceiver |
| | | { |
| | |
| | | #if UNITY_5_4_OR_NEWER |
| | | [ImageEffectAllowedInSceneView] |
| | | #endif |
| | | [RequireComponent(typeof(Camera)), DisallowMultipleComponent, ExecuteInEditMode] |
| | | [RequireComponent(typeof(Camera)), DisallowMultipleComponent, ExecuteAlways] |
| | | [AddComponentMenu("Effects/Post-Processing Behaviour", -1)] |
| | | public class PostProcessingBehaviour : MonoBehaviour |
| | | { |