Ejemplo n.º 1
0
        private static void AddObjectMetadata(Type type)
        {
            if (ObjectData.ContainsKey(type))
            {
                return;
            }

            ObjectMetadata data = new ObjectMetadata();

            if (type.GetInterface("System.Collections.IDictionary") != null)
            {
                data.IsDictionary = true;
            }

            data.Properties = new Dictionary <string, PropertyInfo>();

            foreach (PropertyInfo propertyInfo in type.GetProperties())
            {
                string propertyName = GetPropertyName(propertyInfo);

                if (propertyName == "Item")
                {
                    ParameterInfo[] parameters = propertyInfo.GetIndexParameters();

                    if (parameters.Length != 1)
                    {
                        continue;
                    }

                    if (parameters[0].ParameterType == typeof(string))
                    {
                        data.ElementType = propertyInfo.PropertyType;
                    }

                    continue;
                }

                data.Properties.Add(propertyName, propertyInfo);
            }

            lock (objectMetadataLock)
            {
                try
                {
                    ObjectData.Add(type, data);
                }
                catch (ArgumentException)
                {
                    return;
                }
            }
        }