Kwargs.Net 1.4.0

dotnet add package Kwargs.Net --version 1.4.0                
NuGet\Install-Package Kwargs.Net -Version 1.4.0                
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="Kwargs.Net" Version="1.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kwargs.Net --version 1.4.0                
#r "nuget: Kwargs.Net, 1.4.0"                
#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 Kwargs.Net as a Cake Addin
#addin nuget:?package=Kwargs.Net&version=1.4.0

// Install Kwargs.Net as a Cake Tool
#tool nuget:?package=Kwargs.Net&version=1.4.0                

Kwargs.Net

This library allows dotnet developers to use **kwargs (Keyword Arguments) to create instance or call function like python developers

Example

CreateInstance

using CreateInstance;
using Kwargs.Net;

Dictionary<string, object> kwargs = new()
{
    { "v1", 5 },
    { "s1", "123" },
};
TestClass testClass = Reflection.CreateInstance<TestClass>(Array.Empty<object>(), kwargs)!;
Console.WriteLine($"V1: {testClass.V1}, S1: {testClass.S1}, V2: {testClass.V2}, S2: {testClass.S2}, F1: {testClass.F1}");
// V1: 5, S1: 123, V2: , S2: , F1:

kwargs = new()
{
    { "v2", 7 },
};
testClass = Reflection.CreateInstance<TestClass>(new object[] { 5, "123" }, kwargs)!;
Console.WriteLine($"V1: {testClass.V1}, S1: {testClass.S1}, V2: {testClass.V2}, S2: {testClass.S2}, F1: {testClass.F1}");
// V1: 5, S1: 123, V2: 7, S2: , F1:

kwargs = new()
{
    { "f1", 5f },
    { "s1", "123" },
};
testClass = Reflection.CreateInstance<TestClass>(new object[] { 5 }, kwargs)!;
Console.WriteLine($"V1: {testClass.V1}, S1: {testClass.S1}, V2: {testClass.V2}, S2: {testClass.S2}, F1: {testClass.F1}");
// V1: 5, S1: 123, V2: , S2: , F1: 5
public class TestClass
{
    public int? V1 { get; set; }
    public string? S1 { get; set; }
    public int? V2 { get; set; }
    public string? S2 { get; set; }
    public float? F1 { get; set; }

    public TestClass(int v1, string s1, int v2 = 5, string? s2 = null)
    {
        V1 = v1;
        S1 = s1;
        V2 = v2;
        S2 = s2;
    }

    public TestClass(int v1, string s1)
    {
        V1 = v1;
        S1 = s1;
    }

    public TestClass(int v1, string s1, int? v2 = null, float? f1 = 17)
    {
        V1 = v1;
        S1 = s1;
        V2 = v2;
        F1 = f1;
    }
}

CallStaticFunction

using CallStaticFunction;
using Kwargs.Net;

var result = Reflection.CallFunction(typeof(TestClass), nameof(TestClass.Test), Array.Empty<object>(), new Dictionary<string, object>());
Console.WriteLine(result);
// 123
public class TestClass
{
    public static void Test() { Console.WriteLine("123"); }
    public int Test(int a) { Console.WriteLine(a); return a + 1; }
}

CallObjectFunction

using CallObjectFunction;
using Kwargs.Net;

TestClass testClass = new();
var result = Reflection.CallFunction(testClass, nameof(testClass.Test), Array.Empty<object>(), new Dictionary<string, object> { { "a", 5 } });
Console.WriteLine(result);
// 5
// 6
public class TestClass
{
    public static void Test() { Console.WriteLine("123"); }
    public int Test(int a) { Console.WriteLine(a); return a + 1; }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.0 44,542 3/13/2023
1.3.0 2,757 2/8/2023
1.2.0 5,065 12/2/2022
1.1.0 361 12/2/2022
1.0.0 338 12/1/2022