Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GenderCodeToLabel.cs
1using System.Globalization;
4
6{
10 public class GenderCodeToLabel : IValueConverter, IMarkupExtension
11 {
13 public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
14 {
15 ISO_5218_Gender? Rec;
16
17 if (value is string s)
18 {
19 if (ISO_5218.LetterToGender(s.ToUpper(CultureInfo.InvariantCulture), out Rec) && Rec is not null)
20 return ServiceRef.Localizer[Rec.LocalizedNameId];
21 else if (int.TryParse(s, out int i) && ISO_5218.CodeToGender(i, out Rec) && Rec is not null)
22 return ServiceRef.Localizer[Rec.LocalizedNameId];
23 else
24 return s;
25 }
26 else if (value is int Code && ISO_5218.CodeToGender(Code, out Rec) && Rec is not null)
27 return ServiceRef.Localizer[Rec.LocalizedNameId];
28 else
29 return value ?? string.Empty;
30 }
31
33 public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
34 {
35 return value?.ToString() ?? string.Empty;
36 }
37
39 public object ProvideValue(IServiceProvider serviceProvider)
40 {
41 return this;
42 }
43 }
44}
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:31
static IStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:235
object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
object ProvideValue(IServiceProvider serviceProvider)
object? ConvertBack(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.