/// <summary>
        /// Called by the <b>ProvideAspects</b> method of <see cref="FieldValidationAttribute"/>.
        /// Since a type can have many validated fields but needs a single instance of the current type-level aspect,
        /// this method ensures that each validated type has a single <see cref="TypeValidationAspect"/>
        /// and registers all validated fields in this aspect.
        /// </summary>
        /// <param name="field">Validated field.</param>
        /// <param name="validator">Field validator.</param>
        /// <param name="aspects">Collection to which the new aspect should (eventually) be added.</param>
        internal static IEnumerable<AspectInstance> RegisterFieldValidator( LocationInfo location, FieldValidationAttribute validator)
        {
            Type declaringType = location.DeclaringType;
            TypeValidationAspect instance;

            // Do I have already an aspect for this type?
            if ( !instances.TryGetValue( declaringType.FullName, out instance ) )
            {
                // No? Create one.
                instance = new TypeValidationAspect();
                instances.Add( declaringType.FullName, instance );
                yield return new AspectInstance( declaringType, instance );
            }

            // Index the validator in the new aspect instance.
            instance.validators.Add( validator );
        }
Exemple #2
0
        /// <summary>
        /// Called by the <b>ProvideAspects</b> method of <see cref="FieldValidationAttribute"/>.
        /// Since a type can have many validated fields but needs a single instance of the current type-level aspect,
        /// this method ensures that each validated type has a single <see cref="TypeValidationAspect"/>
        /// and registers all validated fields in this aspect.
        /// </summary>
        /// <param name="field">Validated field.</param>
        /// <param name="validator">Field validator.</param>
        /// <param name="aspects">Collection to which the new aspect should (eventually) be added.</param>
        internal static IEnumerable <AspectInstance> RegisterFieldValidator(LocationInfo location, FieldValidationAttribute validator)
        {
            Type declaringType = location.DeclaringType;
            TypeValidationAspect instance;

            // Do I have already an aspect for this type?
            if (!instances.TryGetValue(declaringType.FullName, out instance))
            {
                // No? Create one.
                instance = new TypeValidationAspect();
                instances.Add(declaringType.FullName, instance);
                yield return(new AspectInstance(declaringType, instance));
            }

            // Index the validator in the new aspect instance.
            instance.validators.Add(validator);
        }