Esempio n. 1
0
 public object Parse(byte[] json)
 {
     _params = Parameters;
     _params.FixValues();
     _globalTypes = _params.UsingGlobalTypes;
     return(new BJsonParser(json, _params.UseUTCtimes).Decode());
 }
Esempio n. 2
0
        /// <summary>
        /// Create a binary json representation for an object with parameter override on this call
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static byte[] ToBJSON(object obj, BJSONParameters param)
        {
            param.FixValues();
            Type t = null;

            if (obj == null)
            {
                return new byte[] { TOKENS.NULL }
            }
            ;
            if (obj.GetType().IsGenericType)
            {
                t = Reflection.Instance.GetGenericTypeDefinition(obj.GetType());// obj.GetType().GetGenericTypeDefinition();
            }
            if (t == typeof(Dictionary <,>) || t == typeof(List <>))
            {
                param.UsingGlobalTypes = false;
            }
            // FEATURE : enable extensions when you can deserialize anon types
            if (param.EnableAnonymousTypes)
            {
                param.UseExtensions = false; param.UsingGlobalTypes = false;
            }

            return(new BJSONSerializer(param).ConvertToBJSON(obj));
        }
Esempio n. 3
0
        public object FillObject(object input, byte[] json)
        {
            _params = Parameters;
            _params.FixValues();
            Dictionary <string, object> ht = new BJsonParser(json, _params.UseUTCtimes).Decode() as Dictionary <string, object>;

            if (ht == null)
            {
                return(null);
            }
            return(ParseDictionary(ht, null, input.GetType(), input));
        }
Esempio n. 4
0
 public deserializer(BJSONParameters param)
 {
     _params = param;
 }
Esempio n. 5
0
 /// <summary>
 /// Create an object from the json with parameter override on this call
 /// </summary>
 /// <param name="json"></param>
 /// <param name="param"></param>
 /// <returns></returns>
 public static object ToObject(byte[] json, BJSONParameters param)
 {
     param.FixValues();
     return(new deserializer(param).ToObject(json, null));
 }
Esempio n. 6
0
 /// <summary>
 /// Create a generic object from the json with parameter override on this call
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="json"></param>
 /// <param name="param"></param>
 /// <returns></returns>
 public static T ToObject <T>(byte[] json, BJSONParameters param)
 {
     return(new deserializer(param).ToObject <T>(json));
 }
Esempio n. 7
0
 internal BJSONSerializer(BJSONParameters param)
 {
     _params    = param;
     _MAX_DEPTH = param.SerializerMaxDepth;
 }
Esempio n. 8
0
 public deserializer(BJSONParameters param)
 {
     _params = param;
     _params = param.MakeCopy();
 }
Esempio n. 9
0
        internal Getters[] GetGetters(Type type, BJSONParameters param)
        {
            Getters[] val = null;
            if (_getterscache.TryGetValue(type, out val))
            {
                return(val);
            }

            PropertyInfo[] props   = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            List <Getters> getters = new List <Getters>();

            foreach (PropertyInfo p in props)
            {
                // CHANGED FOR ** LITEDB ** IgnoreProperty
                if (param.IgnoreProperty != null && p.MetadataToken == param.IgnoreProperty.MetadataToken && p.Module.Equals(param.IgnoreProperty.Module))
                {
                    continue;
                }
                if (!p.CanWrite && param.ShowReadOnlyProperties == false)
                {
                    continue;
                }
                if (param.IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in param.IgnoreAttributes)
                    {
                        if (p.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                GenericGetter g = CreateGetMethod(type, p);
                if (g != null)
                {
                    getters.Add(new Getters {
                        Getter = g, Name = p.Name
                    });
                }
            }

            FieldInfo[] fi = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
            foreach (var f in fi)
            {
                if (param.IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in param.IgnoreAttributes)
                    {
                        if (f.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }

                GenericGetter g = CreateGetField(type, f);
                if (g != null)
                {
                    getters.Add(new Getters {
                        Getter = g, Name = f.Name
                    });
                }
            }

            val = getters.ToArray();
            _getterscache.Add(type, val);
            return(val);
        }
Esempio n. 10
0
        //private bool _circular = false;

        internal BJSONSerializer(BJSONParameters param)
        {
            _params = param;
        }
Esempio n. 11
0
        public object ToObject(byte[] json, Type type)
        {
            _params = Parameters;
            _params.FixValues();
            Type t = null;

            if (type != null && type.IsGenericType)
            {
                t = type.GetGenericTypeDefinition();
            }
            if (t == typeof(Dictionary <,>) || t == typeof(List <>))
            {
                _params.UsingGlobalTypes = false;
            }
            _globalTypes = _params.UsingGlobalTypes;

            var o = new BJsonParser(json, _params.UseUTCtimes).Decode();

#if !SILVERLIGHT
            if (type != null && type == typeof(DataSet))
            {
                return(CreateDataset(o as Dictionary <string, object>, null));
            }

            if (type != null && type == typeof(DataTable))
            {
                return(CreateDataTable(o as Dictionary <string, object>, null));
            }
#endif
            if (o is IDictionary)
            {
                if (type != null && t == typeof(Dictionary <,>)) // deserialize a dictionary
                {
                    return(RootDictionary(o, type));
                }
                else // deserialize an object
                {
                    return(ParseDictionary(o as Dictionary <string, object>, null, type, null));
                }
            }

            if (o is List <object> )
            {
                if (type != null && t == typeof(Dictionary <,>)) // kv format
                {
                    return(RootDictionary(o, type));
                }

                if (type != null && t == typeof(List <>)) // deserialize to generic list
                {
                    return(RootList(o, type));
                }

                if (type == typeof(Hashtable))
                {
                    return(RootHashTable((List <object>)o));
                }
                else
                {
                    return((o as List <object>).ToArray());
                }
            }

            return(o);
        }
Esempio n. 12
0
 public byte[] ToBJSON(object obj)
 {
     _params = Parameters;
     return(ToBJSON(obj, _params));
 }