protected override bool ConditionApplies(ModelInstance root) { // Get the allowed values var allowedValues = GetAllowedValues(root); // Always consider as valid when there are no allowed values if (allowedValues == null) { return(false); } // Value properties if (Property is ModelValueProperty) { // List if (Property.IsList) { // Get the current property value var values = root.GetValue((ModelValueProperty)Property) as IEnumerable; // Determine whether the property value is in the list of allowed values return(!(values == null || values.Cast <object>().All(value => allowedValues.Contains(value)))); } // Value else { // Get the current property value var value = root.GetValue((ModelValueProperty)Property); // Determine whether the property value is in the list of allowed values return(!(value == null || allowedValues.Contains(value))); } } // Reference properties else { // List Property if (Property.IsList) { // Get the current property value ModelInstanceList values = root.GetList((ModelReferenceProperty)Property); // Determine whether the property value is in the list of allowed values return(!(values == null || values.All(value => allowedValues.Contains(value)))); } // Reference Property else { // Get the current property value ModelInstance value = root.GetReference((ModelReferenceProperty)Property); // Determine whether the property value is in the list of allowed values return(!(value == null || allowedValues.Contains(value))); } } }
protected override bool ConditionApplies(ModelInstance root) { // Get the allowed values var allowedValues = GetAllowedValues(root); // Always consider as valid when there are no allowed values if (allowedValues == null) return false; // Value properties if (Property is ModelValueProperty) { // List if (Property.IsList) { // Get the current property value var values = root.GetValue((ModelValueProperty)Property) as IEnumerable; // Determine whether the property value is in the list of allowed values return !(values == null || values.Cast<object>().All(value => allowedValues.Contains(value))); } // Value else { // Get the current property value var value = root.GetValue((ModelValueProperty)Property); // Determine whether the property value is in the list of allowed values return !(value == null || allowedValues.Contains(value)); } } // Reference properties else { // List Property if (Property.IsList) { // Get the current property value ModelInstanceList values = root.GetList((ModelReferenceProperty)Property); // Determine whether the property value is in the list of allowed values return !(values == null || values.All(value => allowedValues.Contains(value))); } // Reference Property else { // Get the current property value ModelInstance value = root.GetReference((ModelReferenceProperty)Property); // Determine whether the property value is in the list of allowed values return !(value == null || allowedValues.Contains(value)); } } }