Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RectangleConverter.cs
Go to the documentation of this file.
7
8namespace System.Drawing;
9
11{
12 private static readonly string[] s_propertySort = new string[4] { "X", "Y", "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 int[] array2 = new int[array.Length];
48 TypeConverter converterTrimUnsafe = TypeDescriptor.GetConverterTrimUnsafe(typeof(int));
49 for (int i = 0; i < array2.Length; i++)
50 {
51 array2[i] = (int)converterTrimUnsafe.ConvertFromString(context, culture, array[i]);
52 }
53 if (array2.Length != 4)
54 {
55 throw new ArgumentException(System.SR.Format(System.SR.TextParseFailedFormat, "text", text2, "x, y, width, height"));
56 }
57 return new Rectangle(array2[0], array2[1], array2[2], array2[3]);
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 Rectangle rectangle)
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(int));
78 string[] value2 = new string[4]
79 {
80 converterTrimUnsafe.ConvertToString(context, culture, rectangle.X),
81 converterTrimUnsafe.ConvertToString(context, culture, rectangle.Y),
82 converterTrimUnsafe.ConvertToString(context, culture, rectangle.Width),
83 converterTrimUnsafe.ConvertToString(context, culture, rectangle.Height)
84 };
85 return string.Join(separator, value2);
86 }
87 if (destinationType == typeof(InstanceDescriptor))
88 {
89 ConstructorInfo constructor = typeof(Rectangle).GetConstructor(new Type[4]
90 {
91 typeof(int),
92 typeof(int),
93 typeof(int),
94 typeof(int)
95 });
96 if (constructor != null)
97 {
98 return new InstanceDescriptor(constructor, new object[4] { rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height });
99 }
100 }
101 }
102 return base.ConvertTo(context, culture, value, destinationType);
103 }
104
105 public override object CreateInstance(ITypeDescriptorContext? context, IDictionary propertyValues)
106 {
107 if (propertyValues == null)
108 {
109 throw new ArgumentNullException("propertyValues");
110 }
111 object obj = propertyValues["X"];
112 object obj2 = propertyValues["Y"];
113 object obj3 = propertyValues["Width"];
114 object obj4 = propertyValues["Height"];
115 if (obj == null || obj2 == null || obj3 == null || obj4 == null || !(obj is int) || !(obj2 is int) || !(obj3 is int) || !(obj4 is int))
116 {
118 }
119 return new Rectangle((int)obj, (int)obj2, (int)obj3, (int)obj4);
120 }
121
123 {
124 return true;
125 }
126
127 [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.")]
128 public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext? context, object? value, Attribute[]? attributes)
129 {
130 PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(Rectangle), attributes);
131 return properties.Sort(s_propertySort);
132 }
133
134 public override bool GetPropertiesSupported(ITypeDescriptorContext? context)
135 {
136 return true;
137 }
138}
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? object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
override bool GetPropertiesSupported(ITypeDescriptorContext? context)
override bool GetCreateInstanceSupported(ITypeDescriptorContext? context)
override object CreateInstance(ITypeDescriptorContext? context, IDictionary propertyValues)
override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext? context, object? value, Attribute[]? attributes)
static readonly string[] s_propertySort
override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
override? object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
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