Inheritance: CssPrimitiveValue
示例#1
0
 public static CssPrimitiveValue Create(Match match, bool readOnly)
 {
     if (match.Groups["length"].Success)
     {
         return(new CssPrimitiveLengthValue(match.Groups["lengthNumber"].Value, match.Groups["lengthUnit"].Value, readOnly));
     }
     if (match.Groups["angle"].Success)
     {
         return(new CssPrimitiveAngleValue(match.Groups["angleNumber"].Value, match.Groups["angleUnit"].Value, readOnly));
     }
     if (match.Groups["funcname"].Success)
     {
         var funcValue = match.Groups["funcname"].Value;
         if (string.Equals(funcValue, "rgb", StringComparison.OrdinalIgnoreCase) ||
             string.Equals(funcValue, "rgba", StringComparison.OrdinalIgnoreCase) ||
             string.Equals(funcValue, "hsl", StringComparison.OrdinalIgnoreCase) ||
             string.Equals(funcValue, "hsla", StringComparison.OrdinalIgnoreCase))
         {
             return(new CssPrimitiveRgbValue(match.Groups["func"].Value, readOnly));
         }
         if (string.Equals(funcValue, "var", StringComparison.OrdinalIgnoreCase))
         {
             return(new CssPrimitiveVarsValue(match.Groups["func"].Value, readOnly));
         }
     }
     if (match.Groups["colorIdent"].Success && CssPrimitiveRgbValue.IsColorName(match.Groups["colorIdent"].Value))
     {
         return(new CssPrimitiveRgbValue(match.Groups["colorIdent"].Value, readOnly));
     }
     return(new CssPrimitiveValue(match, readOnly));
 }
示例#2
0
 public static CssPrimitiveValue Create(Match match, bool readOnly)
 {
     if (match.Groups["length"].Success)
     {
         return(new CssPrimitiveLengthValue(match.Groups["lengthNumber"].Value, match.Groups["lengthUnit"].Value, readOnly));
     }
     if (match.Groups["angle"].Success)
     {
         return(new CssPrimitiveAngleValue(match.Groups["angleNumber"].Value, match.Groups["angleUnit"].Value, readOnly));
     }
     if (match.Groups["funcname"].Success && match.Groups["funcname"].Value == "rgb")
     {
         return(new CssPrimitiveRgbValue(match.Groups["func"].Value, readOnly));
     }
     if (match.Groups["colorIdent"].Success && CssPrimitiveRgbValue.IsColorName(match.Groups["colorIdent"].Value))
     {
         return(new CssPrimitiveRgbValue(match.Groups["colorIdent"].Value, readOnly));
     }
     return(new CssPrimitiveValue(match, readOnly));
 }
    public void TestCssNames()
    {
        Hashtable table = new Hashtable();
                table.Add("maroon", "#800000");
                table.Add("red", "#ff0000");
                table.Add("orange", "#ffA500");
                table.Add("yellow", "#ffff00");
                table.Add("olive", "#808000");
                table.Add("purple", "#800080");
                table.Add("fuchsia", "#ff00ff");
                table.Add("white", "#ffffff");
                table.Add("lime", "#00ff00");
                table.Add("green", "#008000");
                table.Add("navy", "#000080");
                table.Add("blue", "#0000ff");
                table.Add("aqua", "#00ffff");
                table.Add("teal", "#008080");
                table.Add("black", "#000000");
                table.Add("silver", "#c0c0c0");
                table.Add("gray", "#808080");

                IEnumerator colorEnum = table.Keys.GetEnumerator();
                while(colorEnum.MoveNext())
                {
                    string name = (string)colorEnum.Current;
                    string hexColor = (string)table[name];

                    color = new CssPrimitiveRgbValue(name, false);
                    CssPrimitiveRgbValue color2 = new CssPrimitiveRgbValue(hexColor, false);

                    RgbColor rgbColor = (RgbColor)color.GetRgbColorValue();
                    RgbColor rgbColor2 = (RgbColor)color2.GetRgbColorValue();

                    Assert.AreEqual(rgbColor2.Red.GetFloatValue(CssPrimitiveType.Number), rgbColor.Red.GetFloatValue(CssPrimitiveType.Number), name + " red");
                    Assert.AreEqual(rgbColor2.Green.GetFloatValue(CssPrimitiveType.Number), rgbColor.Green.GetFloatValue(CssPrimitiveType.Number), name + " green");
                    Assert.AreEqual(rgbColor2.Blue.GetFloatValue(CssPrimitiveType.Number), rgbColor.Blue.GetFloatValue(CssPrimitiveType.Number), name + " blue");
                }
    }