Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SizeFConverter.cs
Go to the documentation of this file.
7
8namespace System.Drawing;
9
11{
12 private static readonly string[] s_propertySort = new string[2] { "Width", "Height" };
13
14 public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
15 {
16 if (!(sourceType == typeof(string)))
17 {
18 return base.CanConvertFrom(context, sourceType);
19 }
20 return true;
21 }
22
23 public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
24 {
25 if (!(destinationType == typeof(InstanceDescriptor)))
26 {
27 return base.CanConvertTo(context, destinationType);
28 }
29 return true;
30 }
31
32 public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
33 {
34 if (value is string text)
35 {
36 string text2 = text.Trim();
37 if (text2.Length == 0)
38 {
39 return null;
40 }
41 if (culture == null)
42 {
44 }
45 char separator = culture.TextInfo.ListSeparator[0];
46 string[] array = text2.Split(separator);
47 float[] array2 = new float[array.Length];
48 TypeConverter converterTrimUnsafe = TypeDescriptor.GetConverterTrimUnsafe(typeof(float));
49 for (int i = 0; i < array2.Length; i++)
50 {
51 array2[i] = (float)converterTrimUnsafe.ConvertFromString(context, culture, array[i]);
52 }
53 if (array2.Length != 2)
54 {
55 throw new ArgumentException(System.SR.Format(System.SR.TextParseFailedFormat, text2, "Width,Height"));
56 }
57 return new SizeF(array2[0], array2[1]);
58 }
59 return base.ConvertFrom(context, culture, value);
60 }
61
62 public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
63 {
64 if (destinationType == null)
65 {
66 throw new ArgumentNullException("destinationType");
67 }
68 if (value is SizeF sizeF)
69 {
70 if (destinationType == typeof(string))
71 {
72 if (culture == null)
73 {
75 }
76 string separator = culture.TextInfo.ListSeparator + " ";
77 TypeConverter converterTrimUnsafe = TypeDescriptor.GetConverterTrimUnsafe(typeof(float));
78 string[] value2 = new string[2]
79 {
80 converterTrimUnsafe.ConvertToString(context, culture, sizeF.Width),
81 converterTrimUnsafe.ConvertToString(context, culture, sizeF.Height)
82 };
83 return string.Join(separator, value2);
84 }
85 if (destinationType == typeof(InstanceDescriptor))
86 {
87 ConstructorInfo constructor = typeof(SizeF).GetConstructor(new Type[2]
88 {
89 typeof(float),
90 typeof(float)
91 });
92 if (constructor != null)
93 {
94 return new InstanceDescriptor(constructor, new object[2] { sizeF.Width, sizeF.Height });
95 }
96 }
97 }
98 return base.ConvertTo(context, culture, value, destinationType);
99 }
100
101 public override object CreateInstance(ITypeDescriptorContext? context, IDictionary propertyValues)
102 {
103 if (propertyValues == null)
104 {
105 throw new ArgumentNullException("propertyValues");
106 }
107 object obj = propertyValues["Width"];
108 object obj2 = propertyValues["Height"];
109 if (obj == null || obj2 == null || !(obj is float) || !(obj2 is float))
110 {
112 }
113 return new SizeF((float)obj, (float)obj2);
114 }
115
117 {
118 return true;
119 }
120
121 [RequiresUnreferencedCode("The Type of value cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
122 public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext? context, object value, Attribute[]? attributes)
123 {
124 PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(SizeF), attributes);
125 return properties.Sort(s_propertySort);
126 }
127
128 public override bool GetPropertiesSupported(ITypeDescriptorContext? context)
129 {
130 return true;
131 }
132}
string? ConvertToString(object? value)
object? ConvertFromString(string text)
static PropertyDescriptorCollection GetProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static TypeConverter GetConverterTrimUnsafe([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
override bool GetPropertiesSupported(ITypeDescriptorContext? context)
override object CreateInstance(ITypeDescriptorContext? context, IDictionary propertyValues)
override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
override? object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
override? object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext? context, object value, Attribute[]? attributes)
override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
override bool GetCreateInstanceSupported(ITypeDescriptorContext? context)
static readonly string[] s_propertySort
static CultureInfo CurrentCulture
static string PropertyValueInvalidEntry
Definition SR.cs:60
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string TextParseFailedFormat
Definition SR.cs:58
Definition SR.cs:7