YngveHestem.GenericParameterCollection 1.0.2-beta21

This is a prerelease version of YngveHestem.GenericParameterCollection.
There is a newer version of this package available.
See the version list below for details.
dotnet add package YngveHestem.GenericParameterCollection --version 1.0.2-beta21                
NuGet\Install-Package YngveHestem.GenericParameterCollection -Version 1.0.2-beta21                
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="YngveHestem.GenericParameterCollection" Version="1.0.2-beta21" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add YngveHestem.GenericParameterCollection --version 1.0.2-beta21                
#r "nuget: YngveHestem.GenericParameterCollection, 1.0.2-beta21"                
#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 YngveHestem.GenericParameterCollection as a Cake Addin
#addin nuget:?package=YngveHestem.GenericParameterCollection&version=1.0.2-beta21&prerelease

// Install YngveHestem.GenericParameterCollection as a Cake Tool
#tool nuget:?package=YngveHestem.GenericParameterCollection&version=1.0.2-beta21&prerelease                

GenericParameterCollection

ParameterCollection is a simple to use collection for different parameters and types defined with a key. It supports many of the standard types like int, string, double, float, long, DateTime, bool, byte[], enums and more. It can also support nearly every other objects by easy converting the object to it´s own ParameterCollection, which can be nested togheter as parameters. It also supports many of the parameters as IEnumerables (List, Array, etc.). Methods to convert to and from JSON is also included.

How to use this package

The easiest way to use the package is to download it from nuget: https://www.nuget.org/packages/YngveHestem.GenericParameterCollection/

Supported types

Currently, these C#-types are supported out of the box, with some conversion between themselves.

  • int
  • string
  • double
  • long
  • float
  • byte[]
  • bool
  • DateTime
  • ParameterCollection
  • IEnumerable of int
  • IEnumerable of string
  • IEnumerable of double
  • IEnumerable of long
  • IEnumerable of float
  • IEnumerable of bool
  • IEnumerable of DateTime
  • IEnumerable of ParameterCollection
  • Enum-types

Converters for other types are easy to implement.

It also supports selecting an entry between different choices. It also support to select multiple choices.

For the possibillity to differentiate if it should be possible to write multiline or not in a string, and if both the date and time is important in a DateTime, this is also possible to differentiate. This can for example be useful if you for example autogenerates input-forms for a gui.

It is also possible to add multiple parameters to a parameter, which can be used to send much more information togheter with a parameter, or be used to validate the input the way a backend wants it in GUI-level.

When should I use this?

The ParameterCollection was not written to be used instead of classes. This was primarly written to be used with Interfaces or other similar situations where the classes who implements an interface can get nearly any number and different type of response from a user. It is also suitable in other situations where much input from a user is required. This as it is relatively easy to create a GUI with usable controls for the user that can be used over and over again, instead of manually define the controls for each parameter/input by hand.

Concrete example

A concrete example will be a program that let you create an image. This program uses an interface to define everything you can do with the image. Like creating different shapes or blurring image.

Different shapes need different forms of parameters. A rectangle will need a starting point and some hight and width sizes. A circle will need a position and a radius. They might also need for example colors or brushes (or not). Then something like this is needed.

Custom converters

While the package has some default converters built in, you can add nearly any value as a parameter by creating custom converters.

The easiest is to save the value as a ParameterCollection. To create a converter for that you can create a class and inherit from the class ParameterCollectionParameterConverter<TValueType>. TValueType will here be the type that should be converted to/from a ParameterCollection.

If you will convert to any other ParameterType or will convert more in same class, you can create a class that implement the IParameterValueConverter.

GUI-frontends

Here is a list of known packages that will provide an editor for a given framework:

Have you made a package that will fit here? Create an issue with link or create a PR.

Code-Examples

Simple use

In the code-block below, you can see some of the different methods in use.

var parameters = new ParameterCollection();
parameters.Add("1+1", 2);											// int
parameters.Add("5+5", 10);											// int
parameters.Add("Day", true);										// bool
parameters.Add("name", "William Wallace", false);					// string
parameters.Add("description", "- He was a knight." +
	Environment.NewLine + "- He was scottish", true);				// string (defined as multiline)

var answer = parameters.GetByKey<int>("1+1");						// returns 2 as an int
var name = parameters.GetByKey("name");								// returns the name as a string
var parameterTypeDay = parameters.GetParameterType("Day");			// returns ParameterType.Bool
var descriptionType = parameters.GetParameterType("description");   // returns ParameterType.String_Multiline
var nameType = parameters.GetParameterType("name");                 // returns ParameterType.String

var hasKeyNight = parameters.HasKey("Night");                       // returns false

var json = parameters.ToJson();                                     // Convert the collection to a json-string.

var parameters2 = ParameterCollection.FromJson(json);				// Get a new ParameterCollection-object from a json-string.

Add a custom type as a parameter without using custom converters

Below you can see a example for how to define some structures and convert it. The example also show the use of a custom enum, that are supported without any converting.

public class Example
	{
		public void DefineAnExampleSchool()
		{
			var school = new ParameterCollection();
			school.Add("name", "Au High School");
			school.Add("headmaster", new Person
			{
				Name = "Rick Rickerson",
				Gender = Sex.Male,
				BirthDate = new DateTime(1960, 1, 23),
				Summary = "He has done a lot of work"
			}.ToParameterCollection());
        }
	}

    public class Person
    {
		public string Name { get; set; }
		public Sex Gender { get; set; }
		public DateTime BirthDate { get; set; }
		public string Summary { get; set; }

        public ParameterCollection ToParameterCollection()
		{
			return new ParameterCollection
			{
				{ "name", Name, false },
				{ "gender", Gender },
				{ "birthDate", BirthDate, true },
				{ "summary", Summary, true }
			};
		}

		public static Person FromParameterCollection(ParameterCollection person)
		{
			return new Person
			{
				Name = person.GetByKey<string>("name"),
				Gender = person.GetByKey<Sex>("gender"),
				BirthDate = person.GetByKey<DateTime>("birthDate"),
				Summary = person.GetByKey<string>("summary")
			};
		}
    }

    public enum Sex
    {
		Male,
		Female,
		Other
    }
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 (5)

Showing the top 5 NuGet packages that depend on YngveHestem.GenericParameterCollection:

Package Downloads
YngveHestem.GenericParameterCollection.RadzenBlazor

This provides controls for using GenericParameterCollection in a Blazor-application by using Radzen.Blazor-components.

YngveHestem.GenericParameterCollection.EtoForms

This provides controls for using GenericParameterCollection in the GUI-framework Eto.Forms.

YngveHestem.GenericParameterCollection.Maui

This provides controls for using GenericParameterCollection in .NET MAUI.

YngveHestem.GenericParameterCollection.Console

This provides controls for using GenericParameterCollection in a Console-application.

YngveHestem.GenericParameterCollection.Avalonia

This provides controls for using GenericParameterCollection in an AvaloniaUI-application.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.7 202 10/18/2024
1.1.7-beta13 57 10/17/2024
1.1.7-beta12 59 10/16/2024
1.1.7-beta11 73 10/5/2024
1.1.7-beta10 72 10/5/2024
1.1.7-beta09 70 10/2/2024
1.1.7-beta08 69 10/2/2024
1.1.7-beta07 71 10/1/2024
1.1.7-beta06 66 10/1/2024
1.1.7-beta05 66 10/1/2024
1.1.7-beta04 70 9/30/2024
1.1.7-beta03 71 9/30/2024
1.1.7-beta02 81 9/30/2024
1.1.7-beta01 68 9/30/2024
1.1.6 93 9/17/2024
1.1.5 122 7/11/2024
1.1.5-beta02 64 7/11/2024
1.1.5-beta01 73 7/11/2024
1.1.4 138 7/7/2024
1.1.3 101 6/25/2024
1.1.2 102 6/14/2024
1.1.1 180 4/23/2024
1.1.0 254 2/18/2024
1.0.2 197 2/4/2024
1.0.2-beta24 97 1/27/2024
1.0.2-beta23 207 10/28/2023
1.0.2-beta22 177 7/8/2023
1.0.2-beta21 139 7/8/2023
1.0.2-beta20 139 7/8/2023
1.0.2-beta19 186 6/4/2023
1.0.2-beta18 134 6/4/2023
1.0.2-beta17 126 6/4/2023
1.0.2-beta16 174 4/8/2023
1.0.2-beta15 282 4/3/2023
1.0.2-beta14 116 4/2/2023
1.0.2-beta13 131 4/2/2023
1.0.2-beta12 128 4/2/2023
1.0.2-beta11 141 4/2/2023
1.0.2-beta10 134 4/1/2023
1.0.2-beta09 140 4/1/2023
1.0.2-beta08 137 4/1/2023
1.0.2-beta07 140 4/1/2023
1.0.2-beta06 143 4/1/2023
1.0.2-beta05 138 3/22/2023
1.0.2-beta04 136 3/22/2023
1.0.2-beta03 146 3/3/2023
1.0.2-beta02 153 3/2/2023
1.0.2-beta01 161 2/5/2023
1.0.1 301 2/1/2023
1.0.0 288 1/25/2023

Version 1.0.2-beta21:
       - Removed a manual conversion to JToken that is not neccessarry anymore and that created a bug with the last beta.

       Version 1.0.2-beta20:
       - The Parameter-constructors now take in a second customConverter-list, so it is one list that should be saved to the parameter, while the other will only be used when the parameter is created to convert from the value and to the parameter.
       - Removed a lot of the uneccessary constructors for Parameter and add-methods in ParameterCollection. Now, if it has not any special inputs like multiline, choices or similar, it uses the constructor/add-method that takes a object as value. This will make it a little bit easier to manage changes.
       - Remapped all remaining constructors in the Parameter-class to use converters instead of converting directly to JToken.

       Version 1.0.2-beta19:
       - The abstract class ParameterCollectionParameterConverter now has the abstract list-converters as virtual and has default implementations that should fit most scenarios for the list-versions. The default list-check will return true if the list itself is not null (each element is in itself not automatically checked for null), and each element goes through the element-check (the abstract method). If at least one element fails the check it will return false. For the conversion of list the default implementation just creates a list and converts each element (via the abstract method) before returning the resulting list.

       Version 1.0.2-beta18:
       - You can now use the HasKeyCanConvertTo- and CanBeConvertedTo-methods to check against custom converters without adding them to the parameters.

       Version 1.0.2-beta17:
       - You can now send custom converters with the GetValue- and SetValue-methods to use custom converters without needing to add them to the parameters.

       Version 1.0.2-beta16:
       - Fixed a bug in ParameterCollections generic version of method GetByKeyAndType, which made conversions not work as intended.

       Version 1.0.2-beta15:
       - You can now send in null-value in AddCustomConverter without it crash or being added if value is null.
       - Changed some in json-implementation, so ParameterCollection is added as an object instead of directly as an array. This was needed as the earlier implementation did not allow for sending references to custom converters that was added to the ParameterCollection. At the same time we fixed so properties that is null, will not be added to the actual json. This should make the json smaller if few parameters has extra parameters or custom converters.

       Version 1.0.2-beta14:
       - Fixed a bug in DateTimeParameterConverter that made converting list of DateTime not work.

       Version 1.0.2-beta13:
       - Fixed bug in SelectParameterConverter.

       Version 1.0.2-beta12:
       - Fixed so SelectParameterConverter do now allow getting the data as a ParameterConverter.

       Version 1.0.2-beta11:
       - Fixed a possible casting exception between List and Array. Now the default parameter-converters use a function to convert IEnumerables to correct type if possible.
       - Changed bytes-converter to support all IEnumerables of type byte, and not only byte-arrays.
       - Some other small fixes.

       Version 1.0.2-beta10:
       - Simplified conversion between IEnumerables.
       - Some other small changes.

       Version 1.0.2-beta09:
       - Fixed a small bug that prevented SelectionMany to be converted right.
       - Added conversion between string and ParameterType.String_IEnumerable and ParameterType.String_Multiline_IEnumerable

       Version 1.0.2-beta08:
       - Fixed a small bug that prevented DateTimeParameterConverter to convert from DateTime correctly.

       Version 1.0.2-beta07:
       - Moved some of the conversion for SelectOne and SelectMany to converter and at the same time added some more ways to convert.
       - Added the possibillity to add multiple custom converters to Parameter and ParameterCollection with one call.
       - Added a way to get all custom converters added to a Parameter or a ParameterCollection.
       - Small fixes.

       Version 1.0.2-beta06:
       - Moved some of the conversion for Enum to converter and at the same time added some more ways to convert.

       Version 1.0.2-beta05:
       - Fixed a bug that made it impossible to use the object-value constructor to create the Parameter-object

       Version 1.0.2-beta04:
       - Fixed a bug in StringParameterConverter

       Version 1.0.2-beta03:
       - Small bugfixes
       - Custom converters are now possible to send in every Parameter-constructur.

       Version 1.0.2-beta02:
       - Changed how conversion happens, so everything (except Enum, SelectOne and SelectMany), now uses own conversion-classes. This will make it easier to convert to custom types directly.
       - Added possibillity to add any object as a parameter (if it exist a converter).
       - Added possibillity to add custom converters.
       - As custom converters is added, some functions to get value by a specific type are removed.
       - Some functions to check if a parameter can convert to a value is added.

       Version 1.0.2-beta01:
       - Added the possibillity to get the value of an enum as string.
       - Added the possibillity to set a new value of an existing parameter.