Skip to main content

MicroElements source only package: Formatting. Main methods: FormatValue, FormatAsTuple.

Total Downloads
6.8K
6,848
Published
Dec 13, 2021
5y ago

Get Started

dotnet add package MicroElements.Formatting.Sources --version 1.0.1
ProductVersions
.NET Standard
netstandard2.1

README

MicroElements.Formatting.Sources

MicroElements source only package: Formatting.

Source only package does not forces binary reference on it. Just add package and use as code.

Description

FormatValue formats numbers with invariant culture, date types in ISO formats, for collections uses FormatAsTuple

FormatAsTuple formats collections using arguments:

  • separator: The value that uses to separate items. DefaultValue = ", "
  • nullPlaceholder: The value that renders if item is null. DefaultValue = "null"
  • startSymbol: Start symbol. DefaultValue = '('.
  • endSymbol: End symbol. DefaultValue = ')'.
  • formatValue: Func that formats object value to string representation. By default uses FormatValue.
  • maxItems: The max number of items that will be formatted. By default not limited.
  • maxTextLength: Max result text length. Used to limit result text size. DefaultValue=1024
  • trimmedPlaceholder: The value that replaces trimmed part of sequence. DefaultValue = "..."

Usage

new[] { 1, 2 }.FormatAsTuple().Should().Be("(1, 2)");
new[] { 1.1, 2.5 }.FormatAsTuple().Should().Be("(1.1, 2.5)");

new[] { new DateTime(2021, 06, 22), new DateTime(2021, 06, 22, 13, 52, 49, 123)}
   .FormatAsTuple().Should().Be("(2021-06-22, 2021-06-22T13:52:49)");

Enumerable.Range(1, 100)
   .FormatAsTuple(maxItems: 2)
   .Should().Be("(1, 2, ...)");

Enumerable.Repeat("abcde", 100)
   .FormatAsTuple(maxTextLength: 14)
   .Should().Be("(abcde, ab...)")
   .And.Subject.Length.Should().Be(14);

Downloads by Version

Similar & Alternative Packages

Hand-picked matching NuGet libraries based on tags & ecosystem

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.