v3.5.0
What's Changed
Feature: Add interface IFormattingExtensionsToggle to skip formatting (#436)
- Added the
IFormattingExtensionsToggleinterface to allow skipping formatting byIFormatterextensions. - This interface is primarily used by
ISourceextensions that receive it with theISelectorInfoparameter. - By setting
IFormattingExtensionsToggle.DisableFormattingExtensionstotrue, formatting can be skipped. This can be useful when theISourcefound a value inISource.TryEvaluateSelectorwhere default formatting cannot reasonably be done.
Security: Update of System.Text.Json (#435)
- Bumped
System.Text.Jsonto v8.0.4 - Fixed a vulnerability in .NET when calling the JsonSerializer.DeserializeAsyncEnumerable method against an untrusted input using System.Text.Json, which could result in Denial of Service.
Feature: Implement ISpanFormattable for DefaultFormatter (#434)
- Implemented
ISpanFormattableforDefaultFormatter ISpanFormattableis 5% faster than IFormattable, with 24% less allocations// Performance test case Smart.FormatInto(output, null, _placeholder0005Format, 1234567.890123f, 1234567.890123f, 1234567.890123f, 1234567.890123f, 1234567.890123f);
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3737/23H2/2023Update/SunValley3) 13th Gen Intel Core i7-13700K, 1 CPU, 24 logical and 16 physical cores .NET SDK 8.0.302 [Host] : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX2 .NET 8.0 : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX2 Job=.NET 8.0 Runtime=.NET 8.0 | Method | N | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio | |------------------------- |------ |--------------:|------------:|------------:|------:|--------:|-----------:|-------------:|------------:| | ISpanFormattable | 100 | 74.502 us | 0.3693 us | 0.3273 us | 8.52 | 0.05 | 4.0283 | 62.5 KB | 2.76 | | IFormattable | 100 | 77.927 us | 0.5760 us | 0.5388 us | 8.91 | 0.07 | 5.2490 | 82.0 KB | 3.62 |
Feature: ReflectionSource (#426)
- Made
ReflectionSource.TypeCachestaticfor better performance. - If the
staticcache has undesired effects on your code logic, consider to disable the cache (ReflectionSource.IsTypeCacheEnabled = false). - Implemented a mechanism to control the size of
ReflectionSource.TypeCacheand remove the oldest item first.
Enhancement: DictionarySource (#426)
- Dynamics in
DictionarySourcenow use case-sensitivity setting - Cache for
IReadOnlyDictionarynow has instance scope
Refactor: Split off classes Registry and Evaluator from SmartFormatter (#424)
SmartFormatter
- Separated members for handling
ISourceandIFormatterextensions into internal classRegistry - Separated members for evaluating formats into internal class
Evaluator - Existing members of
SmartFormatterremain unchanged and are not yet marked as obsolete
ZCharArray
- Added a lightweight, thread-safe container that rents a buffer from an
ArrayPool<char>and returns it when disposed - Simplifies passing around the buffer without intermediate memory allocations
ZCharArraycontains most frequently used methods for writing data into the underlying buffer- Used in
FormattingInfomethods (see below) for low memory allocation
FormattingInfo
Added methods useful in custom IFormatters:
- public ZCharArray FormattingInfo.FormatAsSpan(IFormatProvider, Format, object?): Works like SmartFormatter.Format(...) for the specified Format
- public ZCharArray FormattingInfo.FormatAsSpan(IFormatProvider, Placeholder, object?): Gets the value for the
Placeholderand applies itsFormat - public bool TryGetValue(Placeholder, out object?): Tries to get the value for a
Placeholder
Evaluator
- Internal class that supplies the methods for evaluating
PlaceholderandFormatobjects - Contains the methods that
FormattingInfouses to evaluatePlaceholderandFormatobjects - Has other methods formerly included in
SmartFormatterthat are now moved toEvaluator - Includes a partial class for handling events in all steps of the evaluation process
Registry
- Internal class that contains all methods for handling
ISourceandIFormatterextensions that have been moved fromSmartFormatter
Feature: Format.HasNested checks for existing Placeholder in Items (#416)
- Added
Format.HasNestedproperty that checks Items for existing Placeholder
Test: Add unit test for nested scope (#404)
- Added unit test for nested scope
Enhancement: Ensure Format instances get returned to object pool (#402)
- Ensured that Format instances get returned to object pool
Refactor: Internal SmartFormat.Pooling classes (#401)
- Simplified pooling classes and made methods and names more consistent
Chore: Remove unused performance test projects (#398)
- Removed unused performance test projects
Fix: Returning a StringBuilder exceeding default capacity to StringBuilderPool (#397)
- Fixed an issue where returning a
StringBuilderexceeding the default capacity toStringBuilderPoolwould throw an exception.
Refactor: Remove code duplications in SmartFormatter (#396)
- Removed code duplications in SmartFormatter
- Unified preprocessor directives
Chore: Remove redundant DependsOnTargets from SmartFormat.csproj (#394)
- Removed redundant DependsOnTargets from SmartFormat.csproj
Full Changelog: v3.4.0...v3.5.0