/// <summary> /// Throws an exception if the value is invalid according to the currently set options /// </summary> /// <param name="Value"></param> /// <returns></returns> public void CheckAndThrow(ICssProperty Owner, CssValue Value) { if (Owner is null) { throw new ArgumentNullException(nameof(Owner)); } if (Value is null) { throw new ArgumentNullException(nameof(Value)); } Contract.EndContractBlock(); if (!Is_Valid_Value_Type(Value.Type)) { throw new CssException($"The property({Enum.GetName(typeof(EMediaFeatureName), Name.Value)}) cannot be set to an {Enum.GetName(typeof(ECssValueTypes), Value.Type)}!"); } switch (Value.Type) { case ECssValueTypes.KEYWORD: { // check this value against our keyword whitelist if (KeywordWhitelist is object && KeywordWhitelist.Count > 0) { //if (!Array.Exists(keywordWhitelist, x => x.Equals(Value.AsString(), StringComparison.InvariantCultureIgnoreCase))) if (!KeywordWhitelist.Contains(Value.AsString())) { throw new CssException($"Property({Enum.GetName(typeof(EMediaFeatureName), Name.Value)}) does not accept '{Value.AsString()}' as a value!"); } } } break; } }
/// <summary> /// Throws an exception if the value is invalid according to the currently set options /// </summary> /// <param name="Value"></param> /// <returns></returns> public void CheckAndThrow(ICssProperty Owner, CssValue Value) { if (Owner is null) { throw new ArgumentNullException(nameof(Owner)); } if (Value is null) { throw new ArgumentNullException(nameof(Value)); } Contract.EndContractBlock(); if (!Is_Valid_Value_Type(Value.Type)) { throw new CssException($"The property({Name}) cannot be set to an {Enum.GetName(typeof(ECssValueTypes), Value.Type)}!"); } switch (Value.Type) { case ECssValueTypes.KEYWORD: { // check this value against our keyword whitelist if (KeywordWhitelist != null && KeywordWhitelist.Count > 0) { if (!KeywordWhitelist.Contains(Value.AsString())) { throw new CssException($"Property({Name}) does not accept '{Value.AsString()}' as a value!"); } } } break; } }