public void Set(IErrorReporter reporter, IToken labelToken, IToken valueToken)
        {
            var labelText = labelToken.Text;

            if (_lookup.TryGetValue(labelText, out var setting))
            {
                var isValueValid = setting.Set(reporter, valueToken);

                if (isValueValid)
                {
                    if (_seenOptions.ContainsKey(labelText))
                    {
                        ReporterHelper.AddWarning(reporter, labelToken, "{0} has already been defined.", labelText);
                    }
                    else
                    {
                        _seenOptions.Add(labelText, true);
                    }
                }
            }
            else
            {
                ReporterHelper.AddError(reporter, labelToken, "'{0}' is not a recognised option.", labelText);
            }
        }
Beispiel #2
0
        protected override bool SetCore(IErrorReporter reporter, IToken valueToken)
        {
            var text = valueToken.Text;

            if (valueToken.Type == SettingTokenType.Label)
            {
                try
                {
                    Value = (T)Enum.Parse(typeof(T), text);
                    return(true);
                }
                catch (ArgumentException)
                {
                    ReporterHelper.AddError(reporter, valueToken, "'{0}' is not a valid {1}.", text, _description);
                    return(false);
                }
            }
            else
            {
                ReporterHelper.AddError(reporter, valueToken, "\"{0}\" is not a valid {1}.", text, _description);
                return(false);
            }
        }