Ejemplo n.º 1
0
        public static PropertyValidator <T> PropertyValidator <T>(Expression <Func <T, object?> > property) where T : ModifiableEntity
        {
            GenerateType <T>();

            var pi = ReflectionTools.GetPropertyInfo(property);

            var dic = validators.GetDefinition(typeof(T));

            PropertyValidator <T>?result = (PropertyValidator <T>?)dic?.TryGetC(pi.Name);

            if (result == null)
            {
                throw new InvalidOperationException("{0} is not defined in {1}, try calling OverridePropertyValidator".FormatWith(pi.PropertyName(), typeof(T).TypeName()));
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static PropertyValidator <T> OverridePropertyValidator <T>(Expression <Func <T, object?> > property) where T : ModifiableEntity
        {
            GenerateType <T>();

            var pi = ReflectionTools.GetPropertyInfo(property);

            var dic = validators.GetDefinition(typeof(T)) !;

            PropertyValidator <T>?result = (PropertyValidator <T>?)dic.TryGetC(pi.Name);

            if (result == null)
            {
                result = new PropertyValidator <T>(pi);
                dic.Add(pi.Name, result);
                validators.ClearCache();
            }

            return(result);
        }