-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTypeConverters.cs
More file actions
54 lines (49 loc) · 2.93 KB
/
Copy pathTypeConverters.cs
File metadata and controls
54 lines (49 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
namespace CustomControls.SwissQRBill {
public class BillOptionsTypeConverter : ExpandableObjectConverter {
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
if(destinationType == typeof(string) && value is BillOptions)
return "(Options)";
return base.ConvertTo(context, culture, value, destinationType);
}
}
public class SwissQRBillScriptsTypeConverter : ExpandableObjectConverter {
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
if(destinationType == typeof(string) && value is XRSwissQRBillScripts)
return "(Swiss QR Bill Scripts)";
return base.ConvertTo(context, culture, value, destinationType);
}
}
public class AlternativeProceduresTypeConverter : ExpandableObjectConverter {
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
if(destinationType == typeof(string) && value is AlternativeProcedures)
return $"({(value).GetType().Name})";
return base.ConvertTo(context, culture, value, destinationType);
}
}
public class AddressTypeConverter : ExpandableObjectConverter {
readonly string[] CombinedSpecificProps = new string[] { nameof(Address.AddressLine1), nameof(Address.AddressLine2) };
readonly string[] StructuredSpecificProps = new string[] { nameof(Address.CountryCode), nameof(Address.BuildingNumber),
nameof(Address.PostalCode), nameof(Address.Street), nameof(Address.Town) };
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
if(destinationType == typeof(string) && value is Address address)
return $"({address.AddressType})";
return base.ConvertTo(context, culture, value, destinationType);
}
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) {
Address address = value as Address;
if(address != null) {
var propertiesCollection = base.GetProperties(context, value, attributes).Cast<PropertyDescriptor>().ToList();
if(address.AddressType == AddressType.Structured)
propertiesCollection.RemoveAll(p => CombinedSpecificProps.Contains(p.Name));
else
propertiesCollection.RemoveAll(p => StructuredSpecificProps.Contains(p.Name));
return new PropertyDescriptorCollection(propertiesCollection.ToArray());
}
return base.GetProperties(context, value, attributes);
}
}
}