public bool MatchesVisitor(string definition) { Mandate.ParameterNotNullOrEmpty(definition, "definition"); SessionSetting sessionSetting; try { sessionSetting = JsonConvert.DeserializeObject <SessionSetting>(definition); } catch (JsonReaderException) { throw new ArgumentException($"Provided definition is not valid JSON: {definition}"); } if (string.IsNullOrEmpty(sessionSetting.Key)) { throw new ArgumentNullException("key", "Session key not set"); } var keyExists = _sessionProvider.KeyExists(sessionSetting.Key); var value = string.Empty; if (keyExists) { value = _sessionProvider.GetValue(sessionSetting.Key); } switch (sessionSetting.Match) { case SessionSettingMatch.Exists: return(keyExists); case SessionSettingMatch.DoesNotExist: return(!keyExists); case SessionSettingMatch.MatchesValue: return(keyExists && MatchesValue(value, sessionSetting.Value)); case SessionSettingMatch.ContainsValue: return(keyExists && ContainsValue(value, sessionSetting.Value)); case SessionSettingMatch.GreaterThanValue: case SessionSettingMatch.GreaterThanOrEqualToValue: case SessionSettingMatch.LessThanValue: case SessionSettingMatch.LessThanOrEqualToValue: return(keyExists && CompareValues(value, sessionSetting.Value, GetComparison(sessionSetting.Match))); case SessionSettingMatch.MatchesRegex: return(keyExists && MatchesRegex(value, sessionSetting.Value)); case SessionSettingMatch.DoesNotMatchRegex: return(keyExists && !MatchesRegex(value, sessionSetting.Value)); default: return(false); } }