ZayniFramework.Common 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package ZayniFramework.Common --version 2.0.1
NuGet\Install-Package ZayniFramework.Common -Version 2.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZayniFramework.Common" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ZayniFramework.Common --version 2.0.1
#r "nuget: ZayniFramework.Common, 2.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ZayniFramework.Common as a Cake Addin
#addin nuget:?package=ZayniFramework.Common&version=2.0.1

// Install ZayniFramework.Common as a Cake Tool
#tool nuget:?package=ZayniFramework.Common&version=2.0.1

Add namespace using in your code.

using ZayniFramework.Common;

Extensions API example.

DateTimeExtension

Test a DateTime range. Use the DateTime.IsBetween() extension method.

var dt    = new DateTime( 2013, 12, 24 );
var begin = new DateTime( 2013, 12, 1 );
var end   = new DateTime( 2013, 12, 31 );
Assert.IsTrue( dt.IsBetween( begin, end ) );
Assert.IsFalse( dt.IsBetween( new DateTime( 2013, 12, 28 ), end ) );

Convert DateTime to a UNIX UTC timestamp. Use the DateTime.ToUnixUtcTimestamp() extension method.

long timestamp = DateTime.Now.ToUnixUtcTimestamp( withMilliseconds: true );
ObjectExtension

Convert an object to a Dictionary. Use the Object.ConvertToDictionary() extension method.

public void ConvertToDictionary_Example()
{
    var model = new UserModel
    {
        Name = "Amber",
        Age  = 23,
        Sex  = "female"
    };

    IDictionary dict = model.ConvertToDictionary();

    string name = dict[ "Name" ] + "";
    string sex  = dict[ "Sex" ]  + "";
    int    age  = int.Parse( dict[ "Age" ] + "" );
}

Convert List<T> to DataTable. Use List<T>.ConvertToDataTable() extension method.

var list = new List<UserModel>() 
{
    new UserModel() 
    {
        Name = "Sylvia",
        Age  = 35,
        Sex  = "Female"
    },
    new UserModel() 
    {
        Name = "Kate",
        Age  = 20,
        Sex  = "Female"
    },
    new UserModel() 
    {
        Name = "John",
        Age  = 23,
        Sex  = "Male"
    }
};

DataTable dt = list.ConvertToDataTable( "SomeTableName" );
Assert.IsNotNull( dt );          

Distinct by conditions. Use IEnumerable<T>.Distinct( Func<TSource, TKey> selector ) extension method.

List<UserModel> models = MakeFakeUsers();
IEnumerable<UserModel> results = models.Distinct( k => new { Name = k.Name, Age = k.Age } );

Deep Clone Object. Use Object.CloneObject() or Object.Clone() extension method.

UserModel clone = obj.CloneObject<UserModel>();
UserModel copy  = obj.Clone<UserModel>();

Invoke the object's method. Use the Object.MethodInvoke() extension method.

public class MemberModel
{
    public string Name { get; set; }

    public string SayHello( string message ) => $"Hello, my name is {Name}. {message}";
}

public void MethodInvoke_Example()
{
    var model  = new MemberModel() { Name = "Sylvia" };
    var result = model.MethodInvoke( "SayHello", "This is a test." );
    Assert.AreEqual( "Hello, my name is Sylvia. This is a test.", result );
}

Get the property value. Use the Object.GetPropertyValue() extension method.

public void GetPropertyValueTest()
{
    var model = new MemberModel()
    {
        Name = "Kate"
    };

    object obj = model.GetPropertyValue( "Name" );
    Assert.IsNotNull( obj );

    string name = obj + "";
    Assert.AreEqual( model.Name, name );

    name = model.GetPropertyValue<string>( "Name" );
    Assert.AreEqual( model.Name, name );
}
StringExtension

Convert a string to byte array. Use the String.ToBytes() extension method. Also demo how to use IEnumerable.IsNotNullAndEmptyArray() entension method.

public void ToBytes_Example()
{
    string test   = "This is a test string.";
    byte[] binary = test.ToBytes();
    Assert.IsTrue( binary.IsNotNullAndEmptyArray() );

    string result = System.Text.Encoding.UTF8.GetString( binary );
    Assert.AreEqual( test, result );
}

Remove the first appeared from a string. Use String.RemoveFirstAppeared() extension method.

string source = "AAABBBCCCAAA";
string result = source.RemoveFirstAppeared( "AAA" );
Assert.AreEqual( "BBBCCCAAA", result );

Remove the last appeared from a string. Use String.RemoveLastAppeared() extension method.

string source = "AAABBBCCCAAACCC";
string result = source.RemoveLastAppeared( "CCC" );
Assert.AreEqual( "AAABBBCCCAAA", result );

Test a string is null or an empty string. Demo the String.IsNullOrEmpty(), String.IsNotNullOrEmpty(), String.FormatTo() extension method.

public void StringIsNullOrEmpty_Example()
{
    string test1 = "";
    Assert.IsTrue( test1.IsNullOrEmpty() );
    Assert.IsFalse( test1.IsNotNullOrEmpty() );

    string test2 = null;
    Assert.IsTrue( test2.IsNullOrEmpty() );
    Assert.IsFalse( test2.IsNotNullOrEmpty() );

    string test3 = "kkk";
    Assert.IsFalse( test3.IsNullOrEmpty() );
    Assert.IsTrue( test3.IsNotNullOrEmpty() );

    string expected1 = "Hello my name is Sylvia. I love Pony.";
    string expected2 = "I'm Pony. Sylvia is my lover.";

    string test4  = "Hello my name is {0}. I love {1}.";
    string result = test4.FormatTo( "Sylvia", "Pony" );
    Assert.AreEqual( expected1, result );

    string result2 = "I'm {0}. {1} is my lover.".FormatTo( "Pony", "Sylvia" );
    Assert.AreEqual( expected2, result2 );
}

Dynamic API example.

Add using.

using ZayniFramework.Common;
using ZayniFramework.Common.Dynamic;

Bind a property to dynamic object in runtime.

Use DynamicBroker.CreateDynamicObject() and DynamicBroker.BindProperty() static method.

public void BindPropertyTest()
{
    dynamic obj = DynamicBroker.CreateDynamicObject();
    Assert.IsNotNull( obj );

    bool isOk = DynamicBroker.BindProperty( obj, "UserName", "Sylvia" ); 
    Assert.IsTrue( isOk );

    string name = obj.UserName;
    Assert.AreEqual( "Sylvia", name );

    bool isOk2 = DynamicBroker.BindProperty( obj, "UserName", "Vivian" );
    Assert.IsTrue( isOk2 );

    string name2 = obj.UserName;
    Assert.AreEqual( "Vivian", name2 );
}

Bind a delegate to dynamic object in runtime.

Use DynamicBroker.BindMethod() static method. Also demo Object.IsNotNull() extension method.

public void BindMethod_Example() 
{
    dynamic obj = DynamicBroker.CreateDynamicObject();
    Assert.IsNotNull( obj );

    bool isOk = DynamicBroker.BindProperty( obj, "UserName", "Sylvia" );
    Assert.IsTrue( isOk );

    string name = obj.UserName;
    Assert.AreEqual( "Sylvia", name );

    SaySomething handler = ( m ) => {
        return string.Format( "Hi, my name is {0}. {1}", obj.UserName, m );
    };

    bool isOk2 = DynamicBroker.BindMethod<SaySomething>( obj, "IntroduceYourself", handler );
    Assert.IsTrue( isOk2 );

    string message = obj.IntroduceYourself( "Nice to meet you." );
    Assert.IsTrue( message.IsNotNullOrEmpty() );
    Assert.AreEqual( "Hi, my name is Sylvia. Nice to meet you.", message );
}

TaskQueue example.

Add using.

using ZayniFramework.Common;
using ZayniFramework.Common.Tasks;

EnQueue an action to TaskQueue.

private static void ExecuteDirectly()
{
    var queue = new TaskQueue( false );

    for ( int i = 0; i < 50; i++ )
    {
        int j = i + 1;

        dynamic queueAction = new QueueAction( new Work().DoSomething );
        queueAction.Index   = j;
        queueAction.Message = new { Test = "123", NumberNo = 55 };
        queue.EnQueue( queueAction );
    }
}

More TaskQueue detail sample here.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (21)

Showing the top 5 NuGet packages that depend on ZayniFramework.Common:

Package Downloads
ZayniFramework.Logging

This is a built-in logging module for ZayniFramework. You can use the zayni.json to configure how the log message should stored. Support file log, elasticsearch log, relational database log (MSSQL, MySQL, Postgres and Oracle), email notification, console log and windows event log. Also you can define the logging event handler, then you can pipe your log message to anywhere you want such as AWS CludeWatch or GCP StackDriver. GitLab Repository: https://gitlab.com/ponylin1985/zayniframework

ZayniFramework.Serialization

The serialization module support JSON (System.Text.Json or Newtonsoft.Json), YAML (YamlDotNet) or XML serialization. You can also define your own serialization component and register it into SerializerFactory. GitLab Repository: https://gitlab.com/ponylin1985/zayniframework

ZayniFramework.Validation

The Validation module provide many kinds of validation attributes and Validator for .NET applications. GitLab Repository: https://gitlab.com/ponylin1985/zayniframework

ZayniFramework.Middle.Service.Entity

The Middle.ServiceHost.Entity define the entities and DTOs for Middle.ServiceHost and Middle.ServiceHost.Client module. GitLab Repository: https://gitlab.com/ponylin1985/zayniframework

ZayniFramework.DataAccess

This is a lightweight ORM framework like Dapper but also provider DbCommand SQL log. Support Microsoft SQL Server, MySQL, PostgreSQL and Oracle database. Also support dynamic ORM. GitLab Repository: https://gitlab.com/ponylin1985/zayniframework

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.142 223 3/19/2024
8.0.141 469 1/4/2024
8.0.140 596 12/17/2023
6.0.138 367 3/19/2024
6.0.137 1,197 9/20/2023
6.0.136 1,077 9/14/2023
6.0.135 1,120 9/10/2023
6.0.134 1,338 7/12/2023
6.0.133 1,394 7/10/2023
6.0.132 1,377 7/7/2023
6.0.131 1,412 6/19/2023
6.0.130 1,450 6/19/2023
6.0.129 13,506 7/2/2022
6.0.128 4,202 1/16/2022
6.0.127 3,991 1/15/2022
6.0.126 3,979 1/15/2022
6.0.125 2,421 1/8/2022
6.0.125-hotfix2 450 1/15/2022
6.0.125-hotfix1 1,351 1/8/2022
6.0.124 2,444 1/7/2022
6.0.123 2,818 11/14/2021
5.0.129 5,522 7/2/2022
5.0.128 5,601 1/16/2022
5.0.125 3,096 1/8/2022
5.0.124 3,012 1/7/2022
5.0.123 3,639 11/14/2021
5.0.122 4,039 10/11/2021
5.0.121 4,158 5/1/2021
3.1.137 2,004 9/20/2023
3.1.136 1,760 9/14/2023
3.1.135.1 339 9/13/2023
3.1.135 1,998 9/10/2023
3.1.134 2,348 7/12/2023
3.1.133 2,432 7/11/2023
3.1.132 2,417 7/8/2023
3.1.131 2,540 6/19/2023
3.1.130 4,565 2/1/2023
3.1.129 8,309 7/2/2022
3.1.128 8,498 1/16/2022
3.1.125 4,385 1/8/2022
3.1.124 4,493 1/7/2022
3.1.123 5,446 11/14/2021
3.1.122 6,152 10/11/2021
3.1.121 6,278 5/1/2021
2.31.120 4,103 3/14/2021
2.30.115 7,547 3/6/2021
2.30.114 3,978 3/6/2021
2.20.101 4,534 3/1/2021
2.19.3 4,116 2/11/2021
2.19.2 16,625 2/6/2021
2.19.1 4,510 1/6/2021
2.19.0 4,592 1/1/2021
2.18.3 7,566 12/27/2020
2.18.2 8,644 8/29/2020
2.18.1 11,684 8/26/2020
2.18.0 8,015 8/20/2020
2.17.135 7,866 8/19/2020
2.17.134 11,894 7/28/2020
2.17.133 7,757 7/27/2020
2.17.132 7,980 7/18/2020
2.17.131 8,007 7/11/2020
2.16.130 7,739 6/13/2020
2.15.128 7,975 6/3/2020
2.15.127 8,010 5/31/2020
2.15.126 8,944 4/30/2020
2.14.122 7,687 4/13/2020
2.13.100 7,858 3/12/2020
2.12.51 7,761 2/18/2020
2.11.50 14,666 2/10/2020
2.10.44 16,364 1/30/2020
2.9.43 16,082 1/11/2020
2.8.42 16,558 1/10/2020
2.8.41 16,106 1/5/2020
2.7.40 15,963 1/2/2020
2.7.39 16,048 1/2/2020
2.7.38 16,703 1/1/2020
2.6.37 16,362 12/23/2019
2.6.35 16,456 12/4/2019
2.6.1 16,077 12/2/2019
2.6.0 16,052 11/28/2019
2.5.2 16,641 11/26/2019
2.5.1 16,007 11/12/2019
2.5.0 15,812 11/9/2019
2.4.3 14,290 10/16/2019
2.4.2 13,394 10/16/2019
2.4.1 13,621 9/20/2019
2.3.113 3,953 3/6/2021
2.3.112 4,006 3/6/2021
2.3.28 13,899 9/19/2019
2.3.27 13,893 8/30/2019
2.3.26 14,087 8/20/2019
2.3.25 13,487 8/12/2019
2.3.22 14,079 7/31/2019
2.3.21 14,263 7/20/2019
2.3.20 13,113 6/22/2019
2.3.19 13,805 6/14/2019
2.3.18 14,334 6/13/2019
2.3.17 13,759 6/13/2019
2.3.15 13,626 6/8/2019
2.3.14 13,691 6/8/2019
2.3.13 14,150 5/30/2019
2.3.12 7,767 5/24/2019
2.3.11 7,674 5/24/2019
2.3.10 7,959 5/21/2019
2.3.9 7,601 5/9/2019
2.3.8 7,935 5/8/2019
2.3.7 7,798 4/30/2019
2.3.6 7,881 4/23/2019
2.3.5 7,851 4/19/2019
2.3.4 7,674 4/18/2019
2.3.3 7,618 4/17/2019
2.3.2 7,676 4/6/2019
2.3.1 7,812 12/15/2018
2.3.0 7,605 12/7/2018
2.2.6 11,289 11/25/2018
2.2.3 4,583 11/23/2018
2.2.2 6,776 11/20/2018
2.2.1 9,176 11/17/2018
2.2.0 6,521 11/16/2018
2.1.0 6,682 11/15/2018
2.0.1 5,522 11/6/2018
2.0.0 5,530 11/4/2018