Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ConvertFromString() [2/2]

static Color System.Drawing.ColorConverterCommon.ConvertFromString ( string strValue,
CultureInfo culture )
inlinestatic

Definition at line 7 of file ColorConverterCommon.cs.

8 {
9 string text = strValue.Trim();
10 if (text.Length == 0)
11 {
12 return Color.Empty;
13 }
14 if (ColorTable.TryGetNamedColor(text, out var result))
15 {
16 return result;
17 }
18 char c = culture.TextInfo.ListSeparator[0];
19 if (!text.Contains(c))
20 {
21 if (text.Length >= 2 && (text[0] == '\'' || text[0] == '"') && text[0] == text[text.Length - 1])
22 {
23 string name = text.Substring(1, text.Length - 2);
24 return Color.FromName(name);
25 }
26 if ((text.Length == 7 && text[0] == '#') || (text.Length == 8 && (text.StartsWith("0x") || text.StartsWith("0X"))) || (text.Length == 8 && (text.StartsWith("&h") || text.StartsWith("&H"))))
27 {
28 return PossibleKnownColor(Color.FromArgb(-16777216 | IntFromString(text, culture)));
29 }
30 }
31 string[] array = text.Split(c);
32 int[] array2 = new int[array.Length];
33 for (int i = 0; i < array2.Length; i++)
34 {
35 array2[i] = IntFromString(array[i], culture);
36 }
37 return array2.Length switch
38 {
39 1 => PossibleKnownColor(Color.FromArgb(array2[0])),
40 3 => PossibleKnownColor(Color.FromArgb(array2[0], array2[1], array2[2])),
41 4 => PossibleKnownColor(Color.FromArgb(array2[0], array2[1], array2[2], array2[3])),
43 };
44 }
static Color PossibleKnownColor(Color color)
static int IntFromString(string text, CultureInfo culture)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string InvalidColor
Definition SR.cs:56
Definition SR.cs:7

References System.array, System.culture, System.Drawing.Color.Empty, System.SR.Format(), System.Drawing.Color.FromArgb(), System.Drawing.Color.FromName(), System.Drawing.ColorConverterCommon.IntFromString(), System.SR.InvalidColor, System.Drawing.ColorConverterCommon.PossibleKnownColor(), System.text, and System.Drawing.ColorTable.TryGetNamedColor().