MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / PointFConverter

Class PointFConverter

TexturedFontEditor/Helper.cs:170–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168 }
169
170 public class PointFConverter : TypeConverter
171 {
172 // Methods
173 public PointFConverter()
174 {
175 }
176 public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
177 {
178 return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType));
179 }
180 public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
181 {
182 return ((destinationType == typeof(PointF)) || base.CanConvertTo(context, destinationType));
183 }
184 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
185 {
186 if (culture == null)
187 culture = CultureInfo.CurrentCulture;
188
189 if (!(value is string))
190 return base.ConvertFrom(context, culture, value);
191
192 string text = ((string)value).Trim();
193 if (text.Length == 0)
194 return null;
195
196 char ch = culture.TextInfo.ListSeparator[0];
197 string[] textArray = text.Split(new char[] { ch });
198 float[] numArray = new float[textArray.Length];
199 if (numArray.Length != 2)
200 throw new ArgumentException("格式不正确");
201
202 TypeConverter converter = TypeDescriptor.GetConverter(typeof(float));
203 for (int i = 0; i < numArray.Length; i++)
204 numArray[i] = (float)converter.ConvertFromString(context, culture, textArray[i]);
205
206 return new PointF(numArray[0], numArray[1]);
207 }
208 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
209 {
210 if (culture == null)
211 culture = CultureInfo.CurrentCulture;
212 if (destinationType == null)
213 throw new ArgumentNullException("destinationType");
214
215 if ((destinationType == typeof(string)) && (value is PointF))
216 {
217 PointF pointf = (PointF)value;
218
219 string separator = culture.TextInfo.ListSeparator + " ";
220 TypeConverter converter = TypeDescriptor.GetConverter(typeof(float));
221 string[] textArray = new string[2];
222 int num = 0;
223 textArray[num++] = converter.ConvertToString(context, culture, pointf.X);
224 textArray[num++] = converter.ConvertToString(context, culture, pointf.Y);
225 return string.Join(separator, textArray);
226 }
227

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected