예제 #1
0
        /// <summary>
        /// Adds all the type checkers to the given scanner.
        /// They basically automatically find CSS properties, units etc in assemblies.
        /// </summary>
        public static void AddToScanner(Modular.AssemblyScanner scanner)
        {
            // CSS functions:
            scanner.FindAllSubTypes(typeof(CssFunction), delegate(Type type){
                // Add it:
                CssFunctions.Add(type);
            });

            // CSS at rules:
            scanner.FindAllSubTypes(typeof(CssAtRule), delegate(Type type){
                // Add it:
                CssAtRules.Add(type);
            });

            // CSS units:
            scanner.FindAllSubTypes(typeof(CssUnit), delegate(Type type){
                // Add it:
                CssUnits.Add(type);
            });

            // CSS keywords:
            scanner.FindAllSubTypes(typeof(CssKeyword), delegate(Type type){
                // Add it:
                CssKeywords.Add(type);
            });

            // CSS properties (secondary pass; requires default values which can be any of the above):
            scanner.FindAllSubTypes(1, typeof(CssProperty), delegate(Type type){
                // Add it:
                CssProperties.Add(type);
            });
        }
예제 #2
0
        /// <summary>Reads a function with the given lowercase name. There must be a bracket at the current read head.</summary>
        public Css.Value ReadFunction(string name)
        {
            // Read off the open bracket:
            Read();

            // Get the global instance for the given function name (lowercase):
            CssFunction globalInstance = name == "" ? null : CssFunctions.Get(name);

            // Read the args:
            Css.Value parameters = null;

            if (globalInstance == null)
            {
                // Unsupported function.
                parameters = ReadValue();
            }
            else
            {
                // Set literal value:
                if (globalInstance.LiteralValue)
                {
                    parameters = ReadLiteralValue();
                }
                else
                {
                    parameters = ReadValue();
                }
            }

            // Skip any junk (which may be e.g. after a quote):
            SkipJunk();

            // Read off the close bracket:
            Read();

            if (name == "")
            {
                // This occurs with nested brackets - it's just a set.
                return(parameters);
            }

            if (globalInstance == null)
            {
                // Don't know what this function is - act like it's not even there.
                return(null);
            }

            // Copy the global instance:
            CssFunction result = globalInstance.Copy() as CssFunction;

            // Make sure params are a set:
            ValueSet set = parameters as ValueSet;

            if (set == null)
            {
                // It's a single value, or null

                if (parameters != null)
                {
                    // Push the single value:
                    result.Values = new Css.Value[] { parameters };
                }
            }
            else
            {
                // Apply the parameters:
                result.Values = set.Values;
            }

            // Tell it that it's ready:
            result.OnValueReady(this);

            // Ok:
            return(result);
        }