src/Shared/EntityFramework/Internal/Validation/EntityValidatorBuilder.cs
// <summary>
// Builds a <see cref="PropertyValidator" /> for the given <paramref name="edmProperty" /> and the corresponding
// <paramref name="clrProperty" />. If the property is a complex type, type level validators will be built here as
// well.
// </summary>
// <param name="clrProperty"> The CLR property to build the validator for. </param>
// <param name="edmProperty"> The EDM property to build the validator for. </param>
// <returns>
// <see cref="PropertyValidator" /> for the given <paramref name="edmProperty" /> . Possibly null if no validation has been specified for this property.
// </returns>
Builds a  for the given  and the corresponding
. If the property is a complex type, type level validators will be built here as
well.
Builds a for the given and the corresponding . If the property is a complex type type level validators will be built here as well .
protected virtual PropertyValidator BuildPropertyValidator(
            PropertyInfo clrProperty, EdmProperty edmProperty, bool buildFacetValidators)
        {
            DebugCheck.NotNull(clrProperty);
            DebugCheck.NotNull(edmProperty);
            Debug.Assert(clrProperty.Name == edmProperty.Name);
            var propertyAttributeValidators = new List<IValidator>();
            var attributes = _attributeProvider.GetAttributes(clrProperty);
            propertyAttributeValidators.AddRange(BuildValidationAttributeValidators(attributes));
            if (edmProperty.TypeUsage.EdmType.BuiltInTypeKind
                == BuiltInTypeKind.ComplexType)
            {
                var complexType = (ComplexType)edmProperty.TypeUsage.EdmType;
                var complexTypeValidator = BuildComplexTypeValidator(clrProperty.PropertyType, complexType);
                return propertyAttributeValidators.Any() || complexTypeValidator != null
                           ? new ComplexPropertyValidator(
                                 clrProperty.Name, propertyAttributeValidators, complexTypeValidator)
                           : null;
            }
            else if (buildFacetValidators)
            {
                propertyAttributeValidators.AddRange(BuildFacetValidators(clrProperty, edmProperty, attributes));
            }
            return propertyAttributeValidators.Any()
                       ? new PropertyValidator(clrProperty.Name, propertyAttributeValidators)
                       : null;
        }
protected virtual PropertyValidator BuildPropertyValidator ( PropertyInfo clrProperty , EdmProperty edmProperty , bool buildFacetValidators ) { DebugCheck . NotNull ( clrProperty ) ; DebugCheck . NotNull ( edmProperty ) ; Debug . Assert ( clrProperty . Name == edmProperty . Name ) ; var propertyAttributeValidators = new List < IValidator > ( ) ; var attributes = _attributeProvider . GetAttributes ( clrProperty ) ; propertyAttributeValidators . AddRange ( BuildValidationAttributeValidators ( attributes ) ) ; if ( edmProperty . TypeUsage . EdmType . BuiltInTypeKind == BuiltInTypeKind . ComplexType ) { var complexType = ( ComplexType ) edmProperty . TypeUsage . EdmType ; var complexTypeValidator = BuildComplexTypeValidator ( clrProperty . PropertyType , complexType ) ; return propertyAttributeValidators . Any ( ) || complexTypeValidator != null ? new ComplexPropertyValidator ( clrProperty . Name , propertyAttributeValidators , complexTypeValidator ) : null ; } else if ( buildFacetValidators ) { propertyAttributeValidators . AddRange ( BuildFacetValidators ( clrProperty , edmProperty , attributes ) ) ; } return propertyAttributeValidators . Any ( ) ? new PropertyValidator ( clrProperty . Name , propertyAttributeValidators ) : null ; }
Builds a  for the given  and the corresponding
.
Builds a for the given and the corresponding .
// this is a complex type so build validators for child properties // finally build validators for type level validation mechanisms defined for this complex type
for the given  . Possibly null if no validation has been specified for this property.
for the given . Possibly null if no validation has been specified for this property .
clrProperty
PropertyInfo
The CLR property to build the validator for.
The CLR property to build the validator for .
edmProperty
EdmProperty
The EDM property to build the validator for.
The EDM property to build the validator for .
buildFacetValidators
bool