jwaliszko / ExpressiveAnnotations

Annotation-based conditional validation library.
MIT License
351 stars 123 forks source link

custom property with RequiredIf #125

Closed JasonLounsbery closed 8 years ago

JasonLounsbery commented 8 years ago

I have a property that determines if a field is required. It always says it is required

[DataMember] [Description("Address Line 1")] [RequiredIf("isRequired(ADDRESS,'STREET') == true", ErrorMessage="Address is Required")] public string ADDRESS { get; set; }

JasonLounsbery commented 8 years ago

The function that determines if it is required or not.
Fieldattributes is a list of properites that are required

[DataMember] public List FieldAttributes { get; set; }

IsRequired is returning the correct value, but the property,'ADDRESS', is still being flagged as required

public bool isRequired(string value,string FieldName) { bool return_bool = false; string v = value;
if (FieldAttributes == null) return false; var hasitems = from Fields in FieldAttributes where Fields.AttributeTypeCode == FieldName select Fields;

        foreach(UserAttributeType u in hasitems)
        {   
            if(u.IsActive)
                return u.Required;

        }
        return return_bool;

    } 

can something like this be done?