Skip to content

zmjack/NStandard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NStandard

.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 Static Badge Static Badge Static Badge Static Badge
.NET Standard Static Badge Static Badge
.NET Framework Static Badge Static Badge Static Badge Static Badge Static Badge Static Badge Static Badge Static Badge Static Badge Static Badge

Install

  • .NET CLI

    dotnet add package NStandard
graph LR
subgraph Upgrade suggestion
0.0.0 --> 0.70.0 --> |Fix errors| Lastest
end
Loading

Recently

Version 0.83.0

  • Adjust the IMeasureExtensions implementations.

Version 0.82.0

  • [Breaking Change] Redesigned the Tree type for better performance.

Version 0.80.0

  • 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 { }

Version 0.78.0

  • StringExtensions.NormalizeNewLine performance improvement.

Version 0.77.0

  • Add new class DataFrame.

Version 0.75.0

  • 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.

Version 0.74.0

  • 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.

Version 0.73.0

  • Add class RgbaColor and provide Json serialization.

Version 0.72.5

  • Adjust IJsonValue structure.
    • Split

    • object Value { get; set; }
    • into

    • object Value { get; }
    • JsonElement RawValue { set; }

Version 0.72.0

  • 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.

Version 0.71.0

  • Adjust the Evaluator code structure to make it easier to extend.

Version 0.70.0

  • 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.


Version 0.68.0

  • Add JsonValueAttribute<T> to declare the Value of its instance to be used when serializing.

Version 0.67.0

  • Fix NullReferenceException when using State<string>.

Version 0.66.0

  • Change the underlying logic of the Sequence class.
  • Optimize the classes in the NStandard.Measures namespace and change the underlying type to decimal.

Version 0.65.1

  • Optimize MathEx.Permut / MathEx.Combin methods and add overflow checks.

Version 0.64.6

  • 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.

Version 0.63.2

  • 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.

Version 0.62.0

  • Add a class Snowflake128 to generate Snowflake ID128 or Guid.

Version 0.61.0

  • Add a class Snowflake to generate Snowflake ID.

Version 0.60.0

  • Add a method PadSlide to create a Sliding with padding.

Version 0.59.0

  • 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)

Version 0.58.0

  • Provide singleton interface: ISingleton<T>.

Version 0.57.0

  • IUnitValue is obsolete, use IMeasurable instead.
  • StorageValue is obsolete, use StorageCapacity instead.
  • New measure classes supported: Measures.Length, Measures.Weight.

Version 0.56.1

  • Add a new structure: MinMaxPair.
  • AsIndexValuePairs has been renamed to Pairs.

Version 0.54.0

  • Add a new method Clone to ValueDiff, which is used to create a shallow copy of the original object.

Version 0.53.0

  • Add new class ValueDiff, describing the value of the state difference.

Version 0.52.0

  • 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.

Version 0.51.0

  • Adjusted JsonXmlSerializer parsing method.
  • Add new class Sequence<T>.
  • Class Flated<T> is obsolete, use Sequence<T> instead.

Version 0.50.0

  • New feature: Provides JsonXmlSerializer to convert JSON to XmlDocument, or XmlNode to JSON.

Version 0.49.0

  • Adjust the EnumOption structure.

Version 0.48.0

  • 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.

Version 0.45.0

  • Breaking change: DateOnlyType and DateTimeType redesigned as Flags.

Version 0.42.0

  • New feature: Provide StartOfSeason / EndOfSeason methods for DateOnly / DateTime / DateTimeOffset.

Version 0.41.0

  • Add new class HashMap<TKey, TValue>.

    It is a IDictionary type that allows the use of null key.

Version 0.39.0

  • DateRangeType has been renamed to DateOnlyType.
  • DateTimeRangeType has been renamed to DateTimeType.

Version: 0.38.0

  • Add new data structure Interval<T> for .NET 7+ to support interval operations.

Version: 0.36.0

  • 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

Version: 0.35.0

  • Optimize PatternSearch performance, add Locate(s) method to Array to find subsequence index.

  • VariantString has been renamed to Variant.

Version: 0.34.0

  • New feature: Any.Compose, to create function composition.

Version: 0.32.0

  • New feature: Any.Chain, Used to transform nested loops to a single loop.

Version: 0.31.0

  • The extension methods Then / For has been renamed to Pipe .

Version: 0.22.0

  • New feature: class FixedSizeQueue.
  • BREAKING CHANGE: SlidingWindow has been redesigned and renamed to Sliding

Version: 0.21.0

  • 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.

Version: 0.17.0

Version: 0.16.0

  • New feature: Any.Text.ComputeHashCode, Computes a fixed hash of a string.

Version: 0.15.0

  • New feature: Any.Flat, flatten array.
  • New feature: Any.ReDim, reallocate array size.

Version: 0.14.0

  • Add Any.Zip function instead of Zipper.Create.

Version: 0.13.0

  • BREAKING CHANGE: To make the name more readable, the extension method class names has been renamed from X... to ...Extensions.

Version: 0.8.40

  • Add struct HashCode for .NET Framework, which behaves like .NET Core.
  • Adjust precompiled macros to make them more reasonable.

About the Official Version (v1.0.0, Not Release)

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.

Utility functions

  • 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

DateTime Extensions

  • 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

Calculation container features

Class Name Description Status
DpContainer Provides dynamic programing feature. Draft

Data-binding features

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:


Pipelines Extension Functions

  • 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);

About

DotNet Core extensions for system library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages