/// <summary>
        /// Enumerates the properties in the specified type and stores the attributes associated with each property
        /// in a <see cref="SchemaAttributes"/> object.
        /// </summary>
        /// <param name="type">The type to reflect on.</param>
        /// <returns>An enumeration of attributes associated with each property in the <paramref name="type"/>.</returns>
        public IEnumerable<SchemaAttributes> GetSchemaAttributes(Type type)
        {
            lock (this.schemaAttributes)
            {
                IEnumerable<SchemaAttributes> result;

                if (!this.schemaAttributes.TryGetValue(type, out result))
                {
                    List<SchemaAttributes> list;

                    list = new List<SchemaAttributes>();
                    result = list;
                    this.schemaAttributes[type] = result;

                    foreach (PropertyInfo info in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        object[] attributes;
                        ConverterAttribute converter;
                        DefaultValueAttribute defaultValue;
                        HasValueIndicatorAttribute hasValueIndicator;
                        SchemaAttributes listEntry;
                        SchemaEntityAttribute schema;
                        List<InheritValueAttribute> inheritanceList;
                        List<string> dependencyList;

                        converter = null;
                        defaultValue = null;
                        dependencyList = new List<string>();
                        hasValueIndicator = null;
                        inheritanceList = new List<InheritValueAttribute>();
                        schema = null;

                        attributes = info.GetCustomAttributes(true);
                        foreach (object attribute in attributes)
                        {
                            Type attributeType;

                            attributeType = attribute.GetType();

                            if (attributeType == typeof(ConverterAttribute))
                            {
                                converter = (ConverterAttribute)attribute;
                            }
                            else if (attributeType == typeof(DefaultValueAttribute))
                            {
                                defaultValue = (DefaultValueAttribute)attribute;
                            }
                            else if (attributeType == typeof(HasValueIndicatorAttribute))
                            {
                                hasValueIndicator = (HasValueIndicatorAttribute)attribute;
                            }
                            else if (attributeType == typeof(SchemaEntityAttribute))
                            {
                                schema = (SchemaEntityAttribute)attribute;
                            }
                            else if (attributeType == typeof(InheritValueAttribute))
                            {
                                inheritanceList.Add((InheritValueAttribute)attribute);
                            }
                            else if (attributeType == typeof(ExplicitOutputDependencyAttribute))
                            {
                                dependencyList.Add(((ExplicitOutputDependencyAttribute)attribute).Property);
                            }
                        }

                        listEntry = new SchemaAttributes(
                                                         info.Name,
                                                         converter,
                                                         defaultValue,
                                                         hasValueIndicator,
                                                         schema,
                                                         inheritanceList,
                                                         dependencyList);
                        list.Add(listEntry);
                    }
                }

                return result;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Enumerates the properties in the specified type and stores the attributes associated with each property
        /// in a <see cref="SchemaAttributes"/> object.
        /// </summary>
        /// <param name="type">The type to reflect on.</param>
        /// <returns>An enumeration of attributes associated with each property in the <paramref name="type"/>.</returns>
        public IEnumerable <SchemaAttributes> GetSchemaAttributes(Type type)
        {
            lock (this.schemaAttributes)
            {
                IEnumerable <SchemaAttributes> result;

                if (!this.schemaAttributes.TryGetValue(type, out result))
                {
                    List <SchemaAttributes> list;

                    list   = new List <SchemaAttributes>();
                    result = list;
                    this.schemaAttributes[type] = result;

                    foreach (PropertyInfo info in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        object[]                                 attributes;
                        ConverterAttribute                       converter;
                        DefaultValueAttribute                    defaultValue;
                        HasValueIndicatorAttribute               hasValueIndicator;
                        SchemaAttributes                         listEntry;
                        SchemaEntityAttribute                    schema;
                        List <InheritValueAttribute>             inheritanceList;
                        List <ExplicitOutputDependencyAttribute> dependencyList;

                        converter         = null;
                        defaultValue      = null;
                        dependencyList    = new List <ExplicitOutputDependencyAttribute>();
                        hasValueIndicator = null;
                        inheritanceList   = new List <InheritValueAttribute>();
                        schema            = null;

                        attributes = info.GetCustomAttributes(true);
                        foreach (object attribute in attributes)
                        {
                            Type attributeType;

                            attributeType = attribute.GetType();

                            if (attributeType == typeof(ConverterAttribute))
                            {
                                converter = (ConverterAttribute)attribute;
                            }
                            else if (attributeType == typeof(DefaultValueAttribute))
                            {
                                defaultValue = (DefaultValueAttribute)attribute;
                            }
                            else if (attributeType == typeof(HasValueIndicatorAttribute))
                            {
                                hasValueIndicator = (HasValueIndicatorAttribute)attribute;
                            }
                            else if (attributeType == typeof(SchemaEntityAttribute))
                            {
                                schema = (SchemaEntityAttribute)attribute;
                            }
                            else if (attributeType == typeof(InheritValueAttribute))
                            {
                                inheritanceList.Add((InheritValueAttribute)attribute);
                            }
                            else if (attributeType == typeof(ExplicitOutputDependencyAttribute))
                            {
                                dependencyList.Add((ExplicitOutputDependencyAttribute)attribute);
                            }
                        }

                        listEntry = new SchemaAttributes(
                            info.Name,
                            converter,
                            defaultValue,
                            hasValueIndicator,
                            schema,
                            inheritanceList,
                            dependencyList);
                        list.Add(listEntry);
                    }
                }

                return(result);
            }
        }