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

◆ ConvertTo() [1/2]

override? object System.Drawing.ColorConverter.ConvertTo ( ITypeDescriptorContext? context,
CultureInfo? culture,
object? value,
Type destinationType )
inlinevirtual

Reimplemented from System.ComponentModel.TypeConverter.

Definition at line 53 of file ColorConverter.cs.

54 {
55 if (destinationType == null)
56 {
57 throw new ArgumentNullException("destinationType");
58 }
59 if (value is Color color)
60 {
61 if (destinationType == typeof(string))
62 {
63 if (color == Color.Empty)
64 {
65 return string.Empty;
66 }
68 {
69 return color.Name;
70 }
71 if (color.IsNamedColor)
72 {
73 return "'" + color.Name + "'";
74 }
75 if (culture == null)
76 {
78 }
79 string separator = culture.TextInfo.ListSeparator + " ";
81 int num = 0;
82 string[] array;
83 if (color.A < byte.MaxValue)
84 {
85 array = new string[4];
86 array[num++] = converterTrimUnsafe.ConvertToString(context, culture, color.A);
87 }
88 else
89 {
90 array = new string[3];
91 }
92 array[num++] = converterTrimUnsafe.ConvertToString(context, culture, color.R);
93 array[num++] = converterTrimUnsafe.ConvertToString(context, culture, color.G);
94 array[num++] = converterTrimUnsafe.ConvertToString(context, culture, color.B);
95 return string.Join(separator, array);
96 }
98 {
100 object[] arguments = null;
101 if (color.IsEmpty)
102 {
103 memberInfo = typeof(Color).GetField("Empty");
104 }
105 else if (System.Drawing.ColorTable.IsKnownNamedColor(color.Name))
106 {
107 memberInfo = typeof(Color).GetProperty(color.Name) ?? typeof(SystemColors).GetProperty(color.Name);
108 }
109 else if (color.A != byte.MaxValue)
110 {
111 memberInfo = typeof(Color).GetMethod("FromArgb", new Type[4]
112 {
113 typeof(int),
114 typeof(int),
115 typeof(int),
116 typeof(int)
117 });
118 arguments = new object[4] { color.A, color.R, color.G, color.B };
119 }
120 else if (color.IsNamedColor)
121 {
122 memberInfo = typeof(Color).GetMethod("FromName", new Type[1] { typeof(string) });
123 arguments = new object[1] { color.Name };
124 }
125 else
126 {
127 memberInfo = typeof(Color).GetMethod("FromArgb", new Type[3]
128 {
129 typeof(int),
130 typeof(int),
131 typeof(int)
132 });
133 arguments = new object[3] { color.R, color.G, color.B };
134 }
135 if (memberInfo != null)
136 {
138 }
139 return null;
140 }
141 }
142 return base.ConvertTo(context, culture, value, destinationType);
143 }
static TypeConverter GetConverterTrimUnsafe([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
static bool IsKnownNamedColor(string name)
Definition ColorTable.cs:38
static CultureInfo CurrentCulture

References System.array, System.culture, System.Globalization.CultureInfo.CurrentCulture, System.Drawing.Color.Empty, System.ComponentModel.TypeDescriptor.GetConverterTrimUnsafe(), System.Drawing.ColorTable.IsKnownNamedColor(), and System.value.