public TypePropertyMetadata(PropertyDescriptor descriptor)
        {
            _propertyDescriptor = descriptor;
            ValidationRules = new List<TypePropertyValidationRuleMetadata>();

            var elementType = TypeUtility.GetElementType(descriptor.PropertyType);

            IsArray = !(elementType == descriptor.PropertyType);

            var propertyAttributes = descriptor.ExplicitAttributes();

            IsKey = null != propertyAttributes[typeof (KeyAttribute)];

            // TODO, 336102, ReadOnlyAttribute for editability?  RIA used EditableAttribute?
            IsReadOnly = propertyAttributes.OfType<ReadOnlyAttribute>().Any(a => a.IsReadOnly);

            var associationAttr = propertyAttributes.OfType<AssociationAttribute>().SingleOrDefault();
            if (associationAttr != null)
                Association = new TypePropertyAssociationMetadata(associationAttr);

            var requiredAttribute = propertyAttributes.OfType<RequiredAttribute>().SingleOrDefault();
            if (requiredAttribute != null)
                ValidationRules.Add(new TypePropertyValidationRuleMetadata(requiredAttribute));

            #region Validation Rules

            var rangeAttribute = (RangeAttribute) propertyAttributes[typeof (RangeAttribute)];
            if (rangeAttribute != null) {
                var operandType = rangeAttribute.OperandType;
                operandType = Nullable.GetUnderlyingType(operandType) ?? operandType;
                if (operandType == typeof (Double)
                    || operandType == typeof (Int16)
                    || operandType == typeof (Int32)
                    || operandType == typeof (Int64)
                    || operandType == typeof (Single))
                    ValidationRules.Add(new TypePropertyValidationRuleMetadata(rangeAttribute));
            }

            var stringLengthAttribute = (StringLengthAttribute) propertyAttributes[typeof (StringLengthAttribute)];
            if (stringLengthAttribute != null)
                ValidationRules.Add(new TypePropertyValidationRuleMetadata(stringLengthAttribute));

            var dataTypeAttribute = (DataTypeAttribute) propertyAttributes[typeof (DataTypeAttribute)];
            if (dataTypeAttribute != null) {
                if (dataTypeAttribute.DataType.Equals(DataType.EmailAddress)
                    || dataTypeAttribute.DataType.Equals(DataType.Url))
                    ValidationRules.Add(new TypePropertyValidationRuleMetadata(dataTypeAttribute));
            }

            #endregion
        }
            public TypePropertyMetadata(PropertyDescriptor descriptor)
            {
                Name = descriptor.Name;

                Type elementType = TypeUtility.GetElementType(descriptor.PropertyType);
                IsArray = !elementType.Equals(descriptor.PropertyType);
                // TODO: What should we do with nullable types here?
                ClrType = elementType;

                AttributeCollection propertyAttributes = TypeDescriptorExtensions.ExplicitAttributes(descriptor);

                // TODO, 336102, ReadOnlyAttribute for editability?  RIA used EditableAttribute?
                ReadOnlyAttribute readonlyAttr = (ReadOnlyAttribute)propertyAttributes[typeof(ReadOnlyAttribute)];
                IsReadOnly = (readonlyAttr != null) ? readonlyAttr.IsReadOnly : false;

                AssociationAttribute associationAttr = (AssociationAttribute)propertyAttributes[typeof(AssociationAttribute)];
                if (associationAttr != null)
                {
                    Association = new TypePropertyAssociationMetadata(associationAttr);
                }

                RequiredAttribute requiredAttribute = (RequiredAttribute)propertyAttributes[typeof(RequiredAttribute)];
                if (requiredAttribute != null)
                {
                    _validationRules.Add(new TypePropertyValidationRuleMetadata(requiredAttribute));
                }

                RangeAttribute rangeAttribute = (RangeAttribute)propertyAttributes[typeof(RangeAttribute)];
                if (rangeAttribute != null)
                {
                    Type operandType = rangeAttribute.OperandType;
                    operandType = Nullable.GetUnderlyingType(operandType) ?? operandType;
                    if (operandType.Equals(typeof(Double))
                        || operandType.Equals(typeof(Int16))
                        || operandType.Equals(typeof(Int32))
                        || operandType.Equals(typeof(Int64))
                        || operandType.Equals(typeof(Single)))
                    {
                        _validationRules.Add(new TypePropertyValidationRuleMetadata(rangeAttribute));
                    }
                }

                StringLengthAttribute stringLengthAttribute = (StringLengthAttribute)propertyAttributes[typeof(StringLengthAttribute)];
                if (stringLengthAttribute != null)
                {
                    _validationRules.Add(new TypePropertyValidationRuleMetadata(stringLengthAttribute));
                }

                DataTypeAttribute dataTypeAttribute = (DataTypeAttribute)propertyAttributes[typeof(DataTypeAttribute)];
                if (dataTypeAttribute != null)
                {
                    if (dataTypeAttribute.DataType.Equals(DataType.EmailAddress)
                        || dataTypeAttribute.DataType.Equals(DataType.Url))
                    {
                        _validationRules.Add(new TypePropertyValidationRuleMetadata(dataTypeAttribute));
                    }
                }
            }
            public TypePropertyMetadata(PropertyDescriptor descriptor)
            {
                Name = descriptor.Name;

                Type elementType = TypeUtility.GetElementType(descriptor.PropertyType);

                IsArray = !elementType.Equals(descriptor.PropertyType);
                // TODO: What should we do with nullable types here?
                ClrType = elementType;

                AttributeCollection propertyAttributes = TypeDescriptorExtensions.ExplicitAttributes(descriptor);

                // TODO, 336102, ReadOnlyAttribute for editability?  RIA used EditableAttribute?
                ReadOnlyAttribute readonlyAttr = (ReadOnlyAttribute)propertyAttributes[typeof(ReadOnlyAttribute)];

                IsReadOnly = (readonlyAttr != null) ? readonlyAttr.IsReadOnly : false;

                AssociationAttribute associationAttr = (AssociationAttribute)propertyAttributes[typeof(AssociationAttribute)];

                if (associationAttr != null)
                {
                    Association = new TypePropertyAssociationMetadata(associationAttr);
                }

                RequiredAttribute requiredAttribute = (RequiredAttribute)propertyAttributes[typeof(RequiredAttribute)];

                if (requiredAttribute != null)
                {
                    _validationRules.Add(new TypePropertyValidationRuleMetadata(requiredAttribute));
                }

                RangeAttribute rangeAttribute = (RangeAttribute)propertyAttributes[typeof(RangeAttribute)];

                if (rangeAttribute != null)
                {
                    Type operandType = rangeAttribute.OperandType;
                    operandType = Nullable.GetUnderlyingType(operandType) ?? operandType;
                    if (operandType.Equals(typeof(Double)) ||
                        operandType.Equals(typeof(Int16)) ||
                        operandType.Equals(typeof(Int32)) ||
                        operandType.Equals(typeof(Int64)) ||
                        operandType.Equals(typeof(Single)))
                    {
                        _validationRules.Add(new TypePropertyValidationRuleMetadata(rangeAttribute));
                    }
                }

                StringLengthAttribute stringLengthAttribute = (StringLengthAttribute)propertyAttributes[typeof(StringLengthAttribute)];

                if (stringLengthAttribute != null)
                {
                    _validationRules.Add(new TypePropertyValidationRuleMetadata(stringLengthAttribute));
                }

                DataTypeAttribute dataTypeAttribute = (DataTypeAttribute)propertyAttributes[typeof(DataTypeAttribute)];

                if (dataTypeAttribute != null)
                {
                    if (dataTypeAttribute.DataType.Equals(DataType.EmailAddress) ||
                        dataTypeAttribute.DataType.Equals(DataType.Url))
                    {
                        _validationRules.Add(new TypePropertyValidationRuleMetadata(dataTypeAttribute));
                    }
                }
            }