Esempio n. 1
0
        /// <summary>
        /// Adds the specified type's fields to the info.
        /// </summary>
        private static void AddFieldInfo(JsonReflectedInfo info, Type type)
        {
            IEnumerator <FieldInfo> fields = FieldEnumerator(type);

            while (fields.MoveNext())
            {
                FieldInfo field     = fields.Current;
                Type      fieldType = field.FieldType;

                //Field must be non-const
                if (field.IsLiteral)
                {
                    continue;
                }
                //JsonIgnoreSerializeAttribute
                if (ShouldIgnoreType(fieldType))
                {
                    continue;
                }

                //Is it enumerable? (except string)
                if (IsEnumerableType(fieldType))
                {
                    info.EnumerableFields.Add(field);
                }
                else
                {
                    info.Fields.Add(field);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the specified type's properties to the info.
        /// </summary>
        private static void AddPropertyInfo(JsonReflectedInfo info, Type type)
        {
            IEnumerator <PropertyInfo> properties = PropertyEnumerator(type);

            while (properties.MoveNext())
            {
                PropertyInfo property     = properties.Current;
                Type         propertyType = property.PropertyType;

                //Indexed property is not supported!
                if (property.GetIndexParameters().Length > 0)
                {
                    continue;
                }
                //JsonIgnoreSerializeAttribute
                if (ShouldIgnoreType(propertyType))
                {
                    continue;
                }

                //Is it enumerable? (except string)
                if (IsEnumerableType(propertyType))
                {
                    info.EnumerableProperties.Add(property);
                }
                else
                {
                    info.Properties.Add(property);
                }
            }
        }
Esempio n. 3
0
 private JsonTypeSerializer(Type type, object obj)
 {
     info = JsonSerializerReflectionCaches.GetInfo(type);
     if (info == null)
     {
         info = JsonSerializerReflectionCaches.Add(type);
     }
     json     = new JsonObject();
     instance = obj;
 }
Esempio n. 4
0
        /// <summary>
        /// Adds the specified anonymous type's properties to the info.
        /// </summary>
        private static void AddAnonymousPropertyInfo(JsonReflectedInfo info, Type type)
        {
            // Get all properties in the type
            PropertyInfo[] properties = type.GetProperties();
            for (int i = 0; i < properties.Length; i++)
            {
                PropertyInfo property = properties[i];

                // If this property is an enumerable type
                if (IsEnumerableType(property.PropertyType))
                {
                    info.EnumerableProperties.Add(property);
                }
                else
                {
                    info.Properties.Add(property);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Extracts the required information from the specified type and adds to the cache list.
        /// Returns the extracted information.
        /// </summary>
        public static JsonReflectedInfo Add(Type type)
        {
            JsonReflectedInfo info = new JsonReflectedInfo(type);

            infos.Add(info);

            if (info.IsAnonymous)
            {
                AddAnonymousPropertyInfo(info, type);
            }
            else
            {
                AddMetaInfo(info, type);

                // We want to avoid unneccessary processes when serialization should be ignored!
                if (!info.ShouldIgnore)
                {
                    AddFieldInfo(info, type);
                    AddPropertyInfo(info, type);
                }
            }

            return(info);
        }
Esempio n. 6
0
 /// <summary>
 /// Adds miscellaneous info of specified type.
 /// </summary>
 private static void AddMetaInfo(JsonReflectedInfo info, Type type)
 {
     info.ShouldIgnore = (
         type.GetCustomAttributes(typeof(JsonIgnoreSerializeAttribute), false).Length > 0
         );
 }