public override void ValidateProperty(BaseMightyMember mightyMember, BaseValidatorAttribute baseAttribute)
        {
            var property          = mightyMember.Property;
            var maxValueAttribute = (MaxValueAttribute)baseAttribute;

            switch (property.propertyType)
            {
            case SerializedPropertyType.Integer:
                if (property.intValue > maxValueAttribute.MaxValue)
                {
                    property.intValue = (int)maxValueAttribute.MaxValue;
                }
                break;

            case SerializedPropertyType.Float:
                if (property.floatValue > maxValueAttribute.MaxValue)
                {
                    property.floatValue = maxValueAttribute.MaxValue;
                }
                break;

            default:
                EditorDrawUtility.DrawHelpBox($"{typeof(MaxValueAttribute).Name} can be used only on int or float fields");
                break;
            }
        }
        public override void ValidateProperty(BaseMightyMember mightyMember, BaseValidatorAttribute baseAttribute)
        {
            var property          = mightyMember.Property;
            var requiredAttribute = (RequiredAttribute)baseAttribute;

            if (property.propertyType == SerializedPropertyType.ObjectReference)
            {
                if (property.objectReferenceValue != null)
                {
                    return;
                }

                var errorMessage = $"{property.name} is required";
                if (!string.IsNullOrEmpty(requiredAttribute.Message))
                {
                    errorMessage = requiredAttribute.Message;
                }

                EditorDrawUtility.DrawHelpBox(errorMessage, MessageType.Error, property.GetTargetObject(), true);
            }
            else
            {
                EditorDrawUtility.DrawHelpBox($"{typeof(RequiredAttribute).Name} works only on reference types");
            }
        }
Esempio n. 3
0
 public void ValidateProperty(MightySerializedField serializedField, BaseValidatorAttribute baseAttribute) =>
 ValidateProperty(serializedField, (T)baseAttribute);
 public abstract void ValidateProperty(BaseMightyMember mightyMember, BaseValidatorAttribute baseAttribute);
Esempio n. 5
0
        public override bool FillFromAttribute(Attributes.BaseAttribute attr)
        {
            if (base.FillFromAttribute(attr))
            {
                return(true);
            }

            //Check campi automatici
            if (attr is BaseAutomaticAttribute)
            {
                if (this.IsAutomatic)
                {
                    throw new SchemaReaderException(this, Resources.SchemaMessages.Prop_NoMultipleAutomatic);
                }

                this.IsAutomatic = true;
                this.Schema.AutoProperties.Add(this);
                this.IsReadonly = true;

                //AUTOINCREMENT
                if (attr is AutoIncrement)
                {
                    this.Schema.AutoIncPk = true;
                    this.ExcludeInsert    = true;
                    this.ExcludeUpdate    = true;

                    //Deve essere numerico e almeno Int32
                    if (!TypeHelper.IsIntegerType(this.Type) || TypeHelper.IntegerSize(this.Type) < 4)
                    {
                        throw new SchemaReaderException(this, Resources.SchemaMessages.Prop_AutoInc_32_Bit);
                    }
                }
                //AUTO INSERT TIMESTAMP
                else if (attr is AutoInsertTimestamp)
                {
                    this.ExcludeUpdate = true;
                }
                //AUTO UPDATE TIMESTAMP
                else if (attr is AutoUpdateTimestamp)
                {
                    //nulla
                }
            }
            //DEFAULT VALUE
            else if (attr is Attributes.DefaultValue)
            {
                this.mDefaultValue = ((Attributes.DefaultValue)attr).ConvertTo(this.Type);
            }
            //CARICA SUL PRIMO ACCESSO
            else if (attr is LoadOnAccess)
            {
                this.LoadOnAccess = true;
            }
            //MODIFICATORI
            else if (attr is BaseModifierAttribute)
            {
                BaseModifierAttribute bm = (BaseModifierAttribute)attr;

                if (bm.CanApplyToProperty(this))
                {
                    if (!this.HasModifiers)
                    {
                        this.AttrModifiers = new List <BaseModifierAttribute>();
                    }

                    this.AttrModifiers.Add(bm);
                }
            }
            //VALIDATORI
            else if (attr is BaseValidatorAttribute)
            {
                BaseValidatorAttribute bv = (BaseValidatorAttribute)attr;

                if (bv.CanApplyToProperty(this))
                {
                    if (!this.HasValidators)
                    {
                        this.AttrValidators = new List <BaseValidatorAttribute>();
                    }

                    this.AttrValidators.Add(bv);
                }
            }
            //Proprieta' criptata su DB
            else if (attr is Encrypted)
            {
                if (!Utils.TypeHelper.IsString(this.Type))
                {
                    throw new SchemaReaderException(this, Resources.SchemaMessages.Prop_Encryped_Only_String);
                }

                this.mEncAttr = (Encrypted)attr;
            }
            //XmlFormatString
            else if (attr is XmlFormatString)
            {
                this.XmlFormatString = ((XmlFormatString)attr).Format;
            }
            else
            {
                throw new NotImplementedException();
            }

            return(true);
        }