Esempio n. 1
0
        private static bool TryRegisterValue(string assignment)
        {
            var value = TypeResolver.Resolve(assignment, _values, _functions);

            if (!value.WasRecognised)
            {
                return(false);
            }
            if (_values.ContainsKey(value.Name))
            {
                _values[value.Name] = value.Resolved;
            }
            else
            {
                _values.TryAddValue(value.Name, value.Resolved);
            }
            return(true);
        }
Esempio n. 2
0
        private static ValueSource ValueSourceFromDictionary(Dictionary <string, object> values)
        {
            values = values ?? new Dictionary <string, object>();
            var valueSource = new ValueSource();

            foreach (var kvp in values)
            {
                var type = EvaluationType.Null;
                if (kvp.Value is float || kvp.Value is decimal)
                {
                    type = EvaluationType.Float;
                }
                if (kvp.Value is int)
                {
                    type = EvaluationType.Int;
                }
                if (kvp.Value is bool)
                {
                    type = EvaluationType.Boolean;
                }
                if (kvp.Value is DateTime)
                {
                    type = EvaluationType.DateTime;
                }
                if (kvp.Value is string)
                {
                    type = EvaluationType.String;
                }
                if (type == EvaluationType.Null)
                {
                    throw new Exception($"Provided value '{kvp.Key}' was null");
                }
                valueSource.TryAddValue(kvp.Key, new EvaluationResult(type, kvp.Value));
            }
            return(valueSource);
        }