Пример #1
0
        private static void AddObjectMetadata(Type type)
        {
            if (JsonMapper.object_metadata.ContainsKey(type))
            {
                return;
            }
            ObjectMetadata value = default(ObjectMetadata);

            if (JsonMapper.HasInterface(type, "System.Collections.IDictionary"))
            {
                value.IsDictionary = true;
            }
            value.Properties = new Dictionary <string, PropertyMetadata>();
            PropertyInfo[] publicInstanceProperties = JsonMapper.GetPublicInstanceProperties(type);
            for (int i = 0; i < publicInstanceProperties.Length; i++)
            {
                PropertyInfo propertyInfo = publicInstanceProperties[i];
                if (propertyInfo.Name == "Item")
                {
                    ParameterInfo[] indexParameters = propertyInfo.GetIndexParameters();
                    if (indexParameters.Length == 1)
                    {
                        if (indexParameters[0].ParameterType == typeof(string))
                        {
                            value.ElementType = propertyInfo.PropertyType;
                        }
                    }
                }
                else
                {
                    PropertyMetadata value2 = default(PropertyMetadata);
                    value2.Info = propertyInfo;
                    value2.Type = propertyInfo.PropertyType;
                    value.Properties.Add(propertyInfo.Name, value2);
                }
            }
            FieldInfo[] fields = type.GetFields();
            for (int j = 0; j < fields.Length; j++)
            {
                FieldInfo        fieldInfo = fields[j];
                PropertyMetadata value3    = default(PropertyMetadata);
                value3.Info    = fieldInfo;
                value3.IsField = true;
                value3.Type    = fieldInfo.FieldType;
                value.Properties.Add(fieldInfo.Name, value3);
            }
            object obj = JsonMapper.object_metadata_lock;

            lock (obj)
            {
                try
                {
                    JsonMapper.object_metadata.Add(type, value);
                }
                catch (ArgumentException)
                {
                }
            }
        }
Пример #2
0
        private static void AddArrayMetadata(Type type)
        {
            if (JsonMapper.array_metadata.ContainsKey(type))
            {
                return;
            }
            ArrayMetadata value = default(ArrayMetadata);

            value.IsArray = type.IsArray;
            if (JsonMapper.HasInterface(type, "System.Collections.IList"))
            {
                value.IsList = true;
            }
            PropertyInfo[] publicInstanceProperties = JsonMapper.GetPublicInstanceProperties(type);
            for (int i = 0; i < publicInstanceProperties.Length; i++)
            {
                PropertyInfo propertyInfo = publicInstanceProperties[i];
                if (!(propertyInfo.Name != "Item"))
                {
                    ParameterInfo[] indexParameters = propertyInfo.GetIndexParameters();
                    if (indexParameters.Length == 1)
                    {
                        if (indexParameters[0].ParameterType == typeof(int))
                        {
                            value.ElementType = propertyInfo.PropertyType;
                        }
                    }
                }
            }
            object obj = JsonMapper.array_metadata_lock;

            lock (obj)
            {
                try
                {
                    JsonMapper.array_metadata.Add(type, value);
                }
                catch (ArgumentException)
                {
                }
            }
        }