Advertisement
Guest User

C# Ternaries

a guest
Feb 23rd, 2024
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | Source Code | 0 0
  1. internal bool IsValidValue(string v, CultureInfo culture = null) =>
  2.   //Changes to these should also result in changes to CsvDataTableReader:ctor
  3.   Type == CsvColumnType.DateTime ?
  4.     DateTime.TryParseExact(v, Format, null, DateTimeStyles.None, out var _) :
  5.   Type == CsvColumnType.Period ?
  6.     Format is not null ? TimeSpan.TryParseExact(v, Format, null, out var _) :
  7.     culture is not null ? TimeSpan.TryParse(v, culture, out var _) :
  8.     TimeSpan.TryParse(v, out var _) :
  9.   Type == CsvColumnType.Float ?
  10.     culture is not null ? Double.TryParse(v, culture, out var _) :
  11.     Double.TryParse(v, out var _) :
  12.   Type == CsvColumnType.Decimal ?
  13.     culture is not null ? Decimal.TryParse(v, culture, out var _) :
  14.     Decimal.TryParse(v, out var _) :
  15.   Type == CsvColumnType.Integer ?
  16.     culture is not null ? Int64.TryParse(v, culture, out var _) :
  17.     Int64.TryParse(v, out var _) :
  18.   true;
  19.  
  20.  
  21.   public Type NullableReflectedType =>
  22.     !Nullable ?
  23.       ReflectedType :
  24.       Type == ColumnDataType.Boolean ? typeof(bool?) :
  25.       Type == ColumnDataType.Decimal ? typeof(decimal?) :
  26.       Type == ColumnDataType.Float ?
  27.         NumberType == SegmentDataType.Float32 ? typeof(float?) :
  28.         NumberType == SegmentDataType.Float64 ? typeof(double?) :
  29.         throw new Exception($"Invalid Number Type ({NumberType}) for Float") :
  30.       Type == ColumnDataType.Guid ? typeof(Guid?) :
  31.       Type == ColumnDataType.Integer ?
  32.         NumberType == SegmentDataType.Int8 ? typeof(sbyte?) :
  33.         NumberType == SegmentDataType.Int16 ? typeof(short?) :
  34.         NumberType == SegmentDataType.Int32 ? typeof(int?) :
  35.         NumberType == SegmentDataType.Int64 ? typeof(long?) :
  36.         NumberType == SegmentDataType.Int128 ? typeof(Int128?) :
  37.         NumberType == SegmentDataType.UInt8 ? typeof(byte?) :
  38.         NumberType == SegmentDataType.UInt16 ? typeof(ushort?) :
  39.         NumberType == SegmentDataType.UInt32 ? typeof(uint?) :
  40.         NumberType == SegmentDataType.UInt64 ? typeof(ulong?) :
  41.         NumberType == SegmentDataType.UInt128 ? typeof(UInt128?) :
  42.         throw new Exception($"Invalid Number Type ({NumberType}) for Number") :
  43.       Type == ColumnDataType.String ? typeof(string) :
  44.       Type == ColumnDataType.TimeSpan ? typeof(TimeSpan?) :
  45.       Type == ColumnDataType.TimeStamp ? typeof(DateTime?) :
  46.       throw new NotImplementedException(Type.ToString());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement