Example #1
0
 // TODO: Put strings into the resources.
 //
 public static string GCollection <T>(this FormatStringUtilitiesHandle <ICollection <T> > hnd, int maxCountOfOutputItems, IFormatProvider formatProvider, Func <int, T, IFormatProvider, string> itemFormatter)
 {
     maxCountOfOutputItems
     .Arg(nameof(maxCountOfOutputItems))
     .EnsureNotLessThanZero();
     //
     if (hnd.Object == null)
     {
         return(FormatStringUtilities.GetNullValueText(formatProvider: formatProvider));
     }
     else
     {
         if (itemFormatter == null)
         {
             itemFormatter = (locIndex, locItem, locFormatProvider) => locItem.FmtStr().G(formatProvider: formatProvider);
         }
         using (var acquiredBuffer = EonStringBuilderUtilities.AcquireBuffer()) {
             var outputBuilder = acquiredBuffer.StringBuilder;
             //
             var collectionSize = hnd.Object.Count;
             outputBuilder.Append($"Коллекция (размер {collectionSize.ToString("d", formatProvider)}):");
             if (maxCountOfOutputItems > 0)
             {
                 var itemCounter = 0;
                 foreach (var item in hnd.Object)
                 {
                     checked { itemCounter++; }
                     outputBuilder.Append(Environment.NewLine);
                     outputBuilder.Append('\x0009');
                     outputBuilder.Append(itemCounter.ToString("d", formatProvider));
                     outputBuilder.Append(")");
                     outputBuilder
                     .Append(
                         value:
                         itemFormatter(arg1: itemCounter - 1, arg2: item, arg3: formatProvider)
                         .FmtStr()
                         .G(formatProvider: formatProvider)
                         .FmtStr()
                         .GNLI2());
                     if (itemCounter == maxCountOfOutputItems)
                     {
                         break;
                     }
                 }
             }
             if (collectionSize > maxCountOfOutputItems)
             {
                 outputBuilder.Append(Environment.NewLine);
                 outputBuilder.Append('\x0009');
                 outputBuilder.Append('…');
             }
             //
             return(outputBuilder.ToString());
         }
     }
 }
Example #2
0
 public static string Short(this FormatStringUtilitiesHandle <MetadataPathName> hnd, IFormatProvider formatProvider = default)
 {
     if (hnd.Object is null)
     {
         return(FormatStringUtilities.GetNullValueText(formatProvider: formatProvider));
     }
     else
     {
         return(hnd.Object.ToString(formatSpecifier: FormatStringUtilities.ShortFormatSpecifier, formatProvider: formatProvider));
     }
 }
Example #3
0
 // TODO: Put strings into the resources.
 //
 public static ArgumentUtilitiesHandle <T> EnsureIsNull <T>(this ArgumentUtilitiesHandle <T> hnd)
     where T : class
 {
     if (!(hnd.Value is null))
     {
         var exceptionMessage = (hnd.IsProp ? $"Invalid value of property '{hnd.Name}'.{Environment.NewLine}" : string.Empty) + $"Expected value '{FormatStringUtilities.GetNullValueText(formatProvider: null)}'.";
         throw
             hnd.ExceptionFactory?.Invoke(message: exceptionMessage)
             ?? new ArgumentOutOfRangeException(message: exceptionMessage, paramName: hnd.Name);
     }
Example #4
0
 public static IFormattable ToFormattableString <T>(this T?value)
     where T : struct
 => value.HasValue ? new Globalization.FormattableString("{0}", value) : new Globalization.FormattableString(format : FormatStringUtilities.GetNullValueText(), args : null);
Example #5
0
 public static IFormattable ToFormattableString <T>(this T value)
     where T : class
 => value is null ? new Globalization.FormattableString(format : FormatStringUtilities.GetNullValueText(), args : null) : new Globalization.FormattableString("{0}", value);
Example #6
0
 public static IFormattable ToFormattableString <T>(this T?value, bool propagateNull)
     where T : struct
 => !value.HasValue ? (propagateNull ? null : new Globalization.FormattableString(format : FormatStringUtilities.GetNullValueText(), args : null)) : new Globalization.FormattableString("{0}", value);
Example #7
0
 public static IFormattable ToFormattableString(this object value)
 => Equals(objA: value, objB: null) ? new Globalization.FormattableString(format: FormatStringUtilities.GetNullValueText(), args: null) : new Globalization.FormattableString("{0}", value);
Example #8
0
 public static string DateTimeZoneIso8601(this FormatStringUtilitiesHandle <DateTime?> hnd)
 => hnd.Object.HasValue ? hnd.Object.Value.ToString(format: "yyyy-MM-ddTHHmmsszzz", provider: CultureInfo.InvariantCulture).Replace(":", string.Empty) : FormatStringUtilities.GetNullValueText(formatProvider: null);
Example #9
0
 public static string RoundTrip(this FormatStringUtilitiesHandle <DateTime?> obj, IFormatProvider formatProvider)
 =>
 obj.Object.HasValue
                 ? obj.Object.Value.ToString(format: "o", provider: formatProvider)
                 : FormatStringUtilities.GetNullValueText(formatProvider: formatProvider);
Example #10
0
 public static string GShort(this FormatStringUtilitiesHandle <DateTime?> obj, IFormatProvider formatProvider)
 =>
 obj.Object.HasValue
                 ? $"{obj.Object.Value.ToString(format: "g", provider: formatProvider)} ({obj.Object.Value.ToString(format: "zzz", provider: formatProvider)})"
                 : FormatStringUtilities.GetNullValueText(formatProvider: formatProvider);
Example #11
0
 public static string RoundTrip(this FormatStringUtilitiesHandle <DateTimeOffset?> obj)
 => obj.Object.HasValue ? obj.Object.Value.ToString(format: "o", formatProvider: null) : FormatStringUtilities.GetNullValueText(formatProvider: null);