Example #1
0
        public static void AddStyle(CompilerState state, string selector, DynamicDictionary style)
        {
            var styleSelector = StyleSelectorParser.Parse(selector);
            var container     = new StyleContainer(styleSelector);

            foreach (var(name, value) in style.GetContents())
            {
                if (value == null)
                {
                    state.Context.Logger.Warning($"Style contains null value for property '{name}'.");
                    continue;
                }

                var propName = StringUtility.ToPascalCase(name);
                if (StyleKeys.TryGetByName(propName, out var styleKey) && state.Context.Converters.TryConvert(value, styleKey.Type, out var propertyValue))
                {
                    styleKey.Set(container, propertyValue);
                }
            }

            state.Document.Styles.Add(container);
        }