TypeSupport 1.0.0

TypeSupport provides tools to give you more information about .Net types and factories for working with objects, collections, enums and more.

There is a newer version of this package available.
See the version list below for details.
Install-Package TypeSupport -Version 1.0.0
dotnet add package TypeSupport --version 1.0.0
<PackageReference Include="TypeSupport" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TypeSupport --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

TypeSupport

A CSharp library that makes it easier to work with Types dynamically by providing extensions and tools that makes your life easier. Additionally, it includes a flexible Object factory for creating and initializing all kinds of types.

Description

The best way to understand what TypeSupport can do is to see it in action! It is used as the foundation for many other packages.

Installation

Install TypeSupport from the Package Manager Console:

PM> Install-Package TypeSupport

Usage

Type Support

Getting started - create a TypeSupport from a type

using TypeSupport;

var type = typeof(MyObject);
var typeSupport = new TypeSupport(type);

or do it using the extensions (we will use this syntax going forward):

using TypeSupport;

var type = typeof(MyObject);
var typeSupport = type.TypeSupport();

get information about an array:

var type = typeof(int[]);
var typeSupport = type.TypeSupport();

var isArray = typeSupport.IsArray; // true
var elementType = typeSupport.ElementType; // int

get information about a Dictionary:

var type = typeof(Dictionary<int, string>);
var typeSupport = type.TypeSupport();

var isArray = typeSupport.IsDictionary; // true
var elementTypes = typeSupport.GenericArgumentTypes; // System.Int32, System.String

get info about an interface:

var type = typeof(IVehicle);
var typeSupport = type.TypeSupport();

var isArray = typeSupport.IsInterface; // true
var classesThatImplementICustomInterface = typeSupport.KnownConcreteTypes;
// [] = Car, Truck, Van, Motorcycle

get info about a class:

[Description("A car object")]
public class Car : IVehicle
{
  public string Name { get; set; }
  public Car() { }
}
var type = typeof(Car);
var typeSupport = type.TypeSupport();

var isArray = typeSupport.HasEmptyConstructor; // true
var attributes = typeSupport.Attributes;
// [] = DescriptionAttribute

working with enums:

public enum Colors : byte
{
  Red = 1,
  Green = 2,
  Blue = 3
}
var type = typeof(Colors);
var typeSupport = type.TypeSupport();

var isEnum = typeSupport.IsEnum; // true
var enumValues = typeSupport.EnumValues;
// [] = <1, Red>, <2, Green>, <3, blue>
var enumType = typeSupport.EnumType; // System.Byte

working with Tuples:

var tupleType = typeof(Tuple<int, string, double>);
var valueTupleType = typeof((IVehicle, string));
var tupleTypeSupport = type.TypeSupport();
var valueTupleTypeSupport = valueTupleType.TypeSupport();

var isTuple = tupleTypeSupport.IsTuple; // true
var isValueTuple = valueTupleTypeSupport.IsValueTuple; // true
var tupleGenericArguments = tupleTypeSupport.GenericArgumentTypes; // System.Int32, System.String, System.Double
var valueTupleGenericArguments = valueTupleTypeSupport.GenericArgumentTypes; // IVehicle, System.String
// there's lots more you can do, such as getting the value from a Tuple instance:

var car = new Car();
var description = "My cool car";
var myTuple = (car, description);
var items = myTuple.GetValueTupleItemObjects();
// [] = Car, "My cool car"

Object factory

Create new objects of any type:

var factory = new ObjectFactory();
var listInstance = factory.CreateEmptyObject<IList<int>>(); // List<int>() 0 elements
var dictionaryInstance = factory.CreateEmptyObject<IDictionary<int, string>>(); // Dictionary<int, string>() 0 elements
var emptyByteArray = factory.CreateEmptyObject<byte[]>(); // byte[0] empty byte array
var byteArray = factory.CreateEmptyObject<byte[]>(length: 64); // byte[64]
var tupleInstance = factory.CreateEmptyObject<(int, string)>(); // tupleInstance.Item1 = 0, tupleInstance.item2 = null
var myComplexObject = factory.CreateEmptyObject<MyComplexObject>();

Create objects without parameterless constructors:

public class CustomObject
{
  public int Id { get; }
  public CustomObject(int id)
  {
    Id = id;
  }
}
var factory = new ObjectFactory();
var myObj = factory.CreateEmptyObject<CustomObject>(); // CustomObject

TypeSupport

A CSharp library that makes it easier to work with Types dynamically by providing extensions and tools that makes your life easier. Additionally, it includes a flexible Object factory for creating and initializing all kinds of types.

Description

The best way to understand what TypeSupport can do is to see it in action! It is used as the foundation for many other packages.

Installation

Install TypeSupport from the Package Manager Console:

PM> Install-Package TypeSupport

Usage

Type Support

Getting started - create a TypeSupport from a type

using TypeSupport;

var type = typeof(MyObject);
var typeSupport = new TypeSupport(type);

or do it using the extensions (we will use this syntax going forward):

using TypeSupport;

var type = typeof(MyObject);
var typeSupport = type.TypeSupport();

get information about an array:

var type = typeof(int[]);
var typeSupport = type.TypeSupport();

var isArray = typeSupport.IsArray; // true
var elementType = typeSupport.ElementType; // int

get information about a Dictionary:

var type = typeof(Dictionary<int, string>);
var typeSupport = type.TypeSupport();

var isArray = typeSupport.IsDictionary; // true
var elementTypes = typeSupport.GenericArgumentTypes; // System.Int32, System.String

get info about an interface:

var type = typeof(IVehicle);
var typeSupport = type.TypeSupport();

var isArray = typeSupport.IsInterface; // true
var classesThatImplementICustomInterface = typeSupport.KnownConcreteTypes;
// [] = Car, Truck, Van, Motorcycle

get info about a class:

[Description("A car object")]
public class Car : IVehicle
{
  public string Name { get; set; }
  public Car() { }
}
var type = typeof(Car);
var typeSupport = type.TypeSupport();

var isArray = typeSupport.HasEmptyConstructor; // true
var attributes = typeSupport.Attributes;
// [] = DescriptionAttribute

working with enums:

public enum Colors : byte
{
  Red = 1,
  Green = 2,
  Blue = 3
}
var type = typeof(Colors);
var typeSupport = type.TypeSupport();

var isEnum = typeSupport.IsEnum; // true
var enumValues = typeSupport.EnumValues;
// [] = <1, Red>, <2, Green>, <3, blue>
var enumType = typeSupport.EnumType; // System.Byte

working with Tuples:

var tupleType = typeof(Tuple<int, string, double>);
var valueTupleType = typeof((IVehicle, string));
var tupleTypeSupport = type.TypeSupport();
var valueTupleTypeSupport = valueTupleType.TypeSupport();

var isTuple = tupleTypeSupport.IsTuple; // true
var isValueTuple = valueTupleTypeSupport.IsValueTuple; // true
var tupleGenericArguments = tupleTypeSupport.GenericArgumentTypes; // System.Int32, System.String, System.Double
var valueTupleGenericArguments = valueTupleTypeSupport.GenericArgumentTypes; // IVehicle, System.String
// there's lots more you can do, such as getting the value from a Tuple instance:

var car = new Car();
var description = "My cool car";
var myTuple = (car, description);
var items = myTuple.GetValueTupleItemObjects();
// [] = Car, "My cool car"

Object factory

Create new objects of any type:

var factory = new ObjectFactory();
var listInstance = factory.CreateEmptyObject<IList<int>>(); // List<int>() 0 elements
var dictionaryInstance = factory.CreateEmptyObject<IDictionary<int, string>>(); // Dictionary<int, string>() 0 elements
var emptyByteArray = factory.CreateEmptyObject<byte[]>(); // byte[0] empty byte array
var byteArray = factory.CreateEmptyObject<byte[]>(length: 64); // byte[64]
var tupleInstance = factory.CreateEmptyObject<(int, string)>(); // tupleInstance.Item1 = 0, tupleInstance.item2 = null
var myComplexObject = factory.CreateEmptyObject<MyComplexObject>();

Create objects without parameterless constructors:

public class CustomObject
{
  public int Id { get; }
  public CustomObject(int id)
  {
    Id = id;
  }
}
var factory = new ObjectFactory();
var myObj = factory.CreateEmptyObject<CustomObject>(); // CustomObject

Release Notes

TypeSupport provides tools to give you more information about .Net types and factories for working with objects, collections, enums and more.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on TypeSupport:

Package Downloads
Blazor-State
blazor-state a MediatR pipeline for Blazor state management
Core-State
A fork of blazor-state. Core State is a MediatR pipeline for Blazor, Xamarin, UWP, WPF state management
ppioli.blazor.state
A MediatR pipeline for Blazor state management - Fork of https://github.com/TimeWarpEngineering/blazor-state with custom changes
HYGE.JsonConverters
JSON converter collection foy System.Text.Json. Currently only support System.Data.DataTable.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on TypeSupport:

Repository Stars
TimeWarpEngineering/blazor-state
Manage client side state in Blazor using MediatR pipeline.

Version History

Version Downloads Last updated
1.1.4 4,657 7/9/2020
1.1.3 1,851 6/9/2020
1.1.0 116 6/9/2020
1.0.108 8,020 4/18/2020
1.0.107 100 4/18/2020
1.0.106 184 4/16/2020
1.0.104 107 4/16/2020
1.0.103 110 4/16/2020
1.0.102 3,234 4/13/2020
1.0.100 2,171 1/8/2020
1.0.99 152 1/7/2020
1.0.98 170 1/7/2020
1.0.97 1,587 12/2/2019
1.0.92 7,288 6/30/2019
1.0.90 18,271 5/22/2019
1.0.89 277 5/22/2019
1.0.88 245 5/22/2019
1.0.86 199 5/22/2019
1.0.85 210 5/22/2019
1.0.79 17,403 5/16/2019
1.0.78 212 5/16/2019
1.0.77 212 5/15/2019
1.0.76 212 5/15/2019
1.0.73 274 5/9/2019
1.0.68 217 5/1/2019
1.0.66 1,032 4/20/2019
1.0.62 249 4/20/2019
1.0.61 249 4/20/2019
1.0.58 222 4/17/2019
1.0.54 244 4/15/2019
1.0.51 289 4/14/2019
1.0.46 32,490 12/20/2018
1.0.45 1,241 12/20/2018
1.0.44 233 12/19/2018
1.0.43 237 12/19/2018
1.0.42 260 12/19/2018
1.0.34 235 12/19/2018
1.0.26 293 12/12/2018
1.0.15 295 12/5/2018
1.0.14 279 12/5/2018
1.0.12 1,136 12/4/2018
1.0.10 29,631 12/2/2018
1.0.8 826 12/2/2018
1.0.7 352 11/30/2018
1.0.6 339 11/29/2018
1.0.5 389 11/29/2018
1.0.4 421 11/28/2018
1.0.3 315 11/22/2018
1.0.2 252 11/22/2018
1.0.1 250 11/22/2018
1.0.0 273 11/21/2018
Show less