.NET extension library for system library.
No depndencies, providing compatible implementations for .NET Framework similar to some of .NET Core functions.
You can use it to get the following support:
- Provide compatibility implementation of some new features of .NET Core for .NET Framework.
- Common data structures and some code patterns.
These frameworks are supported:
Frameworks | Versions |
---|---|
.NET | |
.NET Standard | |
.NET Framework |
-
.NET CLI
dotnet add package NStandard
graph LR
subgraph Upgrade suggestion
0.0.0 --> 0.70.0 --> |Fix errors| Lastest
end
- Adjust the IMeasureExtensions implementations.
- [Breaking Change] Redesigned the Tree type for better performance.
-
All built-in measures have been removed.
-
If necessary, install NStandard.Analyzer and use the following code instead.
-
[Measure("g")] public partial struct g { } [Measure("kg"), Measure<g>(1000)] public partial struct kg { }
-
- StringExtensions.NormalizeNewLine performance improvement.
- Add new class DataFrame.
- Adjust JsonAsConverter to provide circular serialization or deserialization checks.
- [Breaking Change] Remove JsonImplAttribute<T>, use JsonImplAttribute<T, TDeserialize> instead.
- [Breaking Change] Remove all methods or types which marked as error.
- Add JsonAsAttribute to specify class or structure to be serialized according to specified interface.
- [Breaking Change] Adjust JsonImplAttribute, you can now specify interface to be deserialized by specified type by default.
- Add class RgbaColor and provide Json serialization.
- Adjust IJsonValue structure.
-
Split
-
object Value { get; set; }
-
into
-
object Value { get; }
-
JsonElement RawValue { set; }
-
- Breaking Change: Adjust Variant logic to throw an error when conversion is not possible.
- Previously, the default value was returned, which resulted in some erroneous logic not being perceived by users.
- Provide deserialization support for IJsonValue.
- Adjust the Evaluator code structure to make it easier to extend.
- Enable nullable checking.
- Fix some potential issues.
- Breaking Change: Most of the deprecated features have been marked as errors. Please upgrade to version 0.68.0 and follow the prompts to modify them.
Warning
Most of the deprecated features have been marked as errors. Please upgrade to version 0.68.0 and follow the prompts to modify them.
These features will be removed in the next version.
- Add JsonValueAttribute<T> to declare the Value of its instance to be used when serializing.
- Fix NullReferenceException when using State<string>.
- Change the underlying logic of the Sequence class.
- Optimize the classes in the NStandard.Measures namespace and change the underlying type to decimal.
- Optimize MathEx.Permut / MathEx.Combin methods and add overflow checks.
- Add JsonImplAttribute<T> to declare interface to be serialized as its instance.
- Add JsonImplAttribute<T, TSerialize> to declare class to be serialized as the specified interface.
- Remove JsonImplConverterAttribute<T>, use JsonImplAttribute<T> instead.
-
Add new class JsonImplConverter to use instance types when serializing interfaces to Json.
-
Add string extension methods for removing head or tail substrings from a string.
- StringExtensions.TrimStart(this string @this, string trimString)
- StringExtensions.TrimStart(this string @this, params string[] trimStrings)
- StringExtensions.TrimEnd(this string @this, string trimString)
- StringExtensions.TrimEnd(this string @this, params string[] trimStrings)
-
Provide more options for Sliding.
- Add a class Snowflake128 to generate Snowflake ID128 or Guid.
- Add a class Snowflake to generate Snowflake ID.
- Add a method PadSlide to create a Sliding with padding.
- Add a method group to compares two floats/doubles if they are similar.
- Method group: MathEx.Approximately.
- Similar to UnityEngine.Mathf.Approximately, but the tolerance can be specified.
- False:
2.4 + 2.4 - 1.2 == 3.6
- True:
MathEx.Approximately(2.4 + 2.4 - 1.2, 3.6)
- Provide singleton interface: ISingleton<T>.
- IUnitValue is obsolete, use IMeasurable instead.
- StorageValue is obsolete, use StorageCapacity instead.
- New measure classes supported: Measures.Length, Measures.Weight.
- Add a new structure: MinMaxPair.
- AsIndexValuePairs has been renamed to Pairs.
- Add a new method Clone to ValueDiff, which is used to create a shallow copy of the original object.
- Add new class ValueDiff, describing the value of the state difference.
- Add MathEx.Ceiling for calculations that round numbers up to the nearest multiple of significance.
- Add MathEx.Floor for calculations that round numbers down to the nearest multiple of significance.
- MathEx.Permutation is obsolete, use MathEx.Permut instead.
- MathEx.Combination is obsolete, use MathEx.Combin instead.
- Adjusted JsonXmlSerializer parsing method.
- Add new class Sequence<T>.
- Class Flated<T> is obsolete, use Sequence<T> instead.
- New feature: Provides JsonXmlSerializer to convert JSON to XmlDocument, or XmlNode to JSON.
- Adjust the EnumOption structure.
- Breaking change: Simplified wrapper type implementation Ref (reference wrapper).
- Breaking change: Add Val type (value wrapper).
- Breaking change: Remove ValueWrapper, use Val instead.
- Breaking change: Remove VString (the value wrapper type for string), use Val<string> instead.
- Breaking change: DateOnlyType and DateTimeType redesigned as Flags.
- New feature: Provide StartOfSeason / EndOfSeason methods for DateOnly / DateTime / DateTimeOffset.
-
Add new class HashMap<TKey, TValue>.
It is a IDictionary type that allows the use of null key.
- DateRangeType has been renamed to DateOnlyType.
- DateTimeRangeType has been renamed to DateTimeType.
- Add new data structure Interval<T> for .NET 7+ to support interval operations.
-
Provide BitConverterEx class for .NET 7+ to support Int128 and UInt128 related methods.
-
Provide calculation support from IPAddress to UInt32 / UInt128.
- IPAddressEx.Create
- IPAddressExtensions.ToUInt32
- IPAddressExtensions.ToUInt128
-
Provide .NET 7 compatibility scheme for DateTime / DateTimeOffset breaking updates:
.NET 7 calculates Ticks algorithms such as AddDays in units of every 1 tick;
.NET 6 and earlier are calculated every 10'000 ticks.
Provide ToFixed extension method for rounding DateTime every 10 ticks using Banker's Rounding.
var dt = new DateTime(2000, 1, 1).AddDays(9.2); // .NET 6-: // 2000/1/10 4:48:00 630830764800000000 ticks // .NET 7+: // 2000/1/10 4:47:59 630830764799999999 ticks var dtf = dt.ToFixed(); // .NET 6-: // 2000/1/10 4:48:00 630830764800000000 ticks // .NET 7+: // 2000/1/10 4:48:00 630830764800000000 ticks
-
Optimize PatternSearch performance, add Locate(s) method to Array to find subsequence index.
-
VariantString has been renamed to Variant.
- New feature: Any.Compose, to create function composition.
- New feature: Any.Chain, Used to transform nested loops to a single loop.
- The extension methods Then / For has been renamed to Pipe .
- New feature: class FixedSizeQueue.
- BREAKING CHANGE: SlidingWindow has been redesigned and renamed to Sliding。
- BREAKING CHANGE: Use StructTuple instead of ValueTuple to provide better compatibility.
- BREAKING CHANGE: Use Any.Zip instead of Zipper member methods.
- BREAKING CHANGE: Use AsIndexValuePairs instead of AsKeyValuePairs / AsKvPairs methods.
- BREAKING CHANGE: Use Any.Forward instead of ObjectExtension.Forward method.
- BREAKING CHANGE: Use Sync instead of SyncLazy type.
- BREAKING CHANGE: Classes LabelValuePair, Zipper, SyncLazy has been removed.
- New feature: class State, to support data binding.
- Adjust precompiled macros to make them more reasonable.
- New feature: Any.Forward, iterate by depth.
- New feature: ArrayExtensions.Map, projects all elements to an array of the new type.
- New feature: Any.Text.ComputeHashCode, Computes a fixed hash of a string.
- Add Any.Zip function instead of Zipper.Create.
- BREAKING CHANGE: To make the name more readable, the extension method class names has been renamed from X... to ...Extensions.
- Add struct HashCode for .NET Framework, which behaves like .NET Core.
- Adjust precompiled macros to make them more reasonable.
Draft
: Features are designed, but not final. Class members may be redesigned.
Finalized
: Features are designed and finalized. It will not be easily modified in the future unless there are major design flaws.
- Class Any.
Name | Description | Status |
---|---|---|
Any.Chain | Convert multiple layers of nested loops to a single-layer chain. | Finalized |
Any.Create | Creates a instance by the specified function. | Finalized |
Any.Flat | Creates a one-dimensional array containing all elements of the specified multidimensional arrays. | Finalized |
Any.Forward | Computes the element by path and returns the element. | Finalized |
Any.ReDim | Reallocates storage space for an array variable. | Finalized |
Any.Text.ComputeHashCode | Computes a deterministic hash code for a string. | Finalized |
Any.Zip | Applies a specified function to the corresponding elements of many sequences, producing a sequence of the results. | Finalized |
- Class DateTimeExtensions or DateTimeOffsetExtensions. (Document)
Name | Description | Status |
---|---|---|
AddDays | Provides a special arithmetic method for calculating working days or non-working days. | Finalized |
AddTotalYears | Returns a new DateTime that adds the specified diff-number of years to the value of this instance. | Finalized |
AddTotalMonths | Returns a new DateTime that adds the specified diff-number of months to the value of this instance. | Finalized |
StartOf & EndOf | Provides operations for the DateTime / DateTimeOffset to return time to a starting point or advance to an end point. | Finalized |
Week | Gets the number of weeks in a year for the specified date. | Finalized |
WeekInMonth | Gets the number of weeks in a month for the specified date. | Finalized |
Class Name | Description | Status |
---|---|---|
DpContainer | Provides dynamic programing feature. | Draft |
Data binding is very useful feature when we need a dynamic variable that depends on other variables.
It can help us maintain only dependent values and achieve the effect of synchronous changes.
Class Name | Description | Status |
---|---|---|
State | Provides data binding feture for instance. | Draft |
Currently, the following functions still need to be improved:
- Compatibility for .NET Framework
- Dynamic formula calculation
- Numerical operations with units
- Dynamic programming
- SequenceInputStream
- And more...
-
Let
Use a method to initialize each element of an array.
var arr = new int[5]; for (int i = 0; i < arr.Length; i++) { arr[i] = i * 2 + 1; }
Simplify:
var arr = new int[5].Let(i => i * 2 + 1);
-
Pipe (No return value)
Run a task for an object, then return itself.
public class AppSecurity { public Aes Aes = Aes.Create(); public AppSecurity() { Aes.Key = "1234567890123456".Bytes(); } }
Simplify:
public class AppSecurity { public Aes Aes = Aes.Create().Pipe(x => x.Key = "1234567890123456".Bytes()); }
-
Pipe(Has return value)
Casts the object to another object through the specified convert method.
var orderYear = Product.Order.Year; var year = orderYear > 2020 ? orderYear : 2020;
Simplify:
var year = Product.Order.Year.Pipe(y => y > 2020 ? y : 2020);