Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GenderCodeToSymbolAndLabel.cs
1using System.Globalization;
4
6{
10 [AcceptEmptyServiceProvider]
11 public class GenderCodeToSymbolAndLabel : IValueConverter, IMarkupExtension
12 {
14 public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
15 {
16 ISO_5218_Gender? Rec;
17
18 if (value is string s)
19 {
20 if (ISO_5218.LetterToGender(s.ToUpper(CultureInfo.InvariantCulture), out Rec) && Rec is not null)
21 return new string(Rec.Unicode, 1) + "\t" + ServiceRef.Localizer[Rec.LocalizedNameId];
22 else if (int.TryParse(s, out int i) && ISO_5218.CodeToGender(i, out Rec) && Rec is not null)
23 return new string(Rec.Unicode, 1) + "\t" + ServiceRef.Localizer[Rec.LocalizedNameId];
24 else
25 return s;
26 }
27 else if (value is int Code && ISO_5218.CodeToGender(Code, out Rec) && Rec is not null)
28 return new string(Rec.Unicode, 1) + "\t" + ServiceRef.Localizer[Rec.LocalizedNameId];
29 else
30 return value ?? string.Empty;
31 }
32
34 public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
35 {
36 return value?.ToString() ?? string.Empty;
37 }
38
40 public object ProvideValue(IServiceProvider serviceProvider)
41 {
42 return this;
43 }
44 }
45}
Static class containing ISO 5218 gender codes
Definition: ISO_5218.cs:9
static bool CodeToGender(int Code, out ISO_5218_Gender? Gender)
Tries to get the gender label corresponding to an ISO 5218 gender code.
Definition: ISO_5218.cs:19
static bool LetterToGender(string Letter, out ISO_5218_Gender? Gender)
Tries to get the gender label corresponding to an ISO 5218 gender code.
Definition: ISO_5218.cs:40
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IReportingStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:370
Converts a gender code to a Unicode symbol followed by a label.
object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
class ISO_5218_Gender(string Gender, int Code, string Letter, string LocalizedNameId, char Unicode)
Contains one record of the ISO 5218 data set.