Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NullableDateTimeConverter.cs
2{
6 public class NullableDateTimeConverter : IValueConverter
7 {
8 public object Convert(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
9 {
10 // Ensure value is DateTime? and provide DateTime.Now if null
11 return (value as DateTime?) ?? DateTime.Today.Date;
12 }
13
14 public object? ConvertBack(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
15 {
16 // If the value is a DateTime, return it; otherwise, return null
17 return value is DateTime DateTime ? DateTime : null;
18 }
19 }
20}
Converts a nullable DateTime to a DateTime, defaulting to DateTime.Now if null.