Ejemplo n.º 1
0
        /// <summary>
        /// Adds a unit by its type.
        /// </summary>
        /// <param name='unitType'>The type of the unit to add.</param>
        public static void Add(Type unitType)
        {
            if (AllEnd == null)
            {
                // Create the sets:
                AllEnd   = new Dictionary <char, CssUnitHandlers>();
                AllStart = new Dictionary <char, CssUnitHandlers>();
            }

            // Instance it:
            CssUnit unit = (CssUnit)Activator.CreateInstance(unitType);

            string[] pre  = unit.PreText;
            string[] post = unit.PostText;

            if (pre != null)
            {
                AddToSet(pre, AllStart, unit);
            }

            if (post != null)
            {
                AddToSet(post, AllEnd, unit);
            }
        }
Ejemplo n.º 2
0
        /// <summary>Adds a CSS at rule to the global set.</summary>
        /// <param name="cssUnit">The at rule to add.</param>
        /// <returns>True if adding it was successful.</returns>
        private static void AddToSet(string[] names, Dictionary <char, CssUnitHandlers> set, CssUnit cssUnit)
        {
            for (int i = 0; i < names.Length; i++)
            {
                string text = names[i];

                char first = text[0];

                CssUnitHandlers handlers;
                if (!set.TryGetValue(first, out handlers))
                {
                    // Create it:
                    handlers           = new CssUnitHandlers();
                    handlers.Character = first;
                    set[first]         = handlers;
                }

                handlers.Add(text, cssUnit);
            }
        }