TypeSupport 1.1.7
See the version list below for details.
dotnet add package TypeSupport --version 1.1.7
NuGet\Install-Package TypeSupport -Version 1.1.7
<PackageReference Include="TypeSupport" Version="1.1.7" />
paket add TypeSupport --version 1.1.7
#r "nuget: TypeSupport, 1.1.7"
// Install TypeSupport as a Cake Addin #addin nuget:?package=TypeSupport&version=1.1.7 // Install TypeSupport as a Cake Tool #tool nuget:?package=TypeSupport&version=1.1.7
TypeSupport
A CSharp library that makes it easier to work with Types dynamically. TypeSupport 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 ExtendedType(type);
or do it using the extensions (we will use this syntax going forward):
using TypeSupport;
var type = typeof(MyObject);
var typeSupport = type.GetExtendedType();
get information about an array:
var type = typeof(int[]);
var typeSupport = type.GetExtendedType();
var isArray = typeSupport.IsArray; // true
var elementType = typeSupport.ElementType; // int
get information about a Dictionary:
var type = typeof(Dictionary<int, string>);
var typeSupport = type.GetExtendedType();
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.GetExtendedType();
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.GetExtendedType();
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.GetExtendedType();
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.GetExtendedType();
var valueTupleTypeSupport = valueTupleType.GetExtendedType();
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>(); // myObj.GetType() == typeof(CustomObject)
You can instruct the Object factory on how to map abstract interfaces when creating instances:
var typeRegistry = TypeRegistry.Configure((config) => {
config.AddMapping<IVehicle, Car>();
});
var factory = new ObjectFactory(typeRegistry);
var car = factory.CreateEmptyObject<IVehicle>(); // car.GetType() == typeof(Car)
You can also register custom factories:
var typeRegistry = TypeRegistry.Configure((config) => {
config.AddFactory<IVehicle, Car>(() => new Car(Color.Red));
});
var factory = new ObjectFactory(typeRegistry);
var car = factory.CreateEmptyObject<IVehicle>(); // car.GetType() == typeof(Car)
Capabilities
- All basic types, enums, generics, collections and enumerables
- Internal caching of type examination
- Constructor analysis (empty constructors, parameterized constructors)
- Easy listing of valid Enum values
- Easy listing of concrete types implementing an interface
- Easy listing of attributes
- Easy listing of generic arguments
- Easy listing of properties/fields
- Easy listing of implemented interfaces
- Easy listing of Tuple/ValueTuple types
- Nullable type detection
- Custom collection information detection
- Primitive / Struct detection
- Anonymous type detection
- High performance testing and optimization
Product | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.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 is compatible. |
.NET Framework | net40 is compatible. net403 was computed. net45 is compatible. net451 was computed. net452 was computed. net46 is compatible. net461 is compatible. net462 is compatible. net463 was computed. net47 is compatible. net471 is compatible. net472 is compatible. net48 is compatible. 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. |
-
.NETFramework 4.0
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.6.1
- No dependencies.
-
.NETFramework 4.6.2
- No dependencies.
-
.NETFramework 4.7
- No dependencies.
-
.NETFramework 4.7.1
- No dependencies.
-
.NETFramework 4.7.2
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETStandard 2.0
- System.Reflection.Emit (>= 4.3.0)
-
.NETStandard 2.1
- System.Reflection.Emit (>= 4.3.0)
-
net5.0
- System.Reflection.Emit (>= 4.3.0)
NuGet packages (16)
Showing the top 5 NuGet packages that depend on TypeSupport:
Package | Downloads |
---|---|
Blazor-State
A Blazor state management library by TimeWarp |
|
AnySerializer
Serialize and deserialize any object without decoration/attributes. |
|
Core-State
A fork of the Core state management library by TimeWarp for use in .Net Maui |
|
Binner.Model.Common
Binner common model library |
|
Binner.StorageProvider.MySql
MySql storage provider for Binner |
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on TypeSupport:
Repository | Stars |
---|---|
TimeWarpEngineering/timewarp-state
A Blazor State management library by TimeWarp.
|
|
replaysMike/Binner
Open source parts inventory system for makers, electronics hobby, and professional engineers
|
|
replaysMike/AnyDiff
A CSharp (C#) diff library that allows you to diff two objects and get a list of the differences back.
|
Version | Downloads | Last updated |
---|---|---|
1.2.0 | 109,845 | 3/14/2023 |
1.1.12 | 169,290 | 9/15/2021 |
1.1.11 | 489 | 8/10/2021 |
1.1.10 | 843 | 7/29/2021 |
1.1.8 | 482 | 7/28/2021 |
1.1.7 | 489 | 7/28/2021 |
1.1.4 | 114,415 | 7/9/2020 |
1.1.3 | 5,013 | 6/9/2020 |
1.1.0 | 535 | 6/9/2020 |
1.0.108 | 34,797 | 4/18/2020 |
1.0.107 | 523 | 4/18/2020 |
1.0.106 | 739 | 4/16/2020 |
1.0.104 | 514 | 4/16/2020 |
1.0.103 | 526 | 4/16/2020 |
1.0.102 | 8,099 | 4/13/2020 |
1.0.100 | 7,258 | 1/8/2020 |
1.0.99 | 582 | 1/7/2020 |
1.0.98 | 562 | 1/7/2020 |
1.0.97 | 3,333 | 12/2/2019 |
1.0.92 | 13,512 | 6/30/2019 |
1.0.90 | 87,003 | 5/22/2019 |
1.0.89 | 1,038 | 5/22/2019 |
1.0.88 | 867 | 5/22/2019 |
1.0.86 | 657 | 5/22/2019 |
1.0.85 | 643 | 5/22/2019 |
1.0.79 | 96,899 | 5/16/2019 |
1.0.78 | 624 | 5/16/2019 |
1.0.77 | 674 | 5/15/2019 |
1.0.76 | 648 | 5/15/2019 |
1.0.73 | 711 | 5/9/2019 |
1.0.68 | 647 | 5/1/2019 |
1.0.66 | 3,074 | 4/20/2019 |
1.0.62 | 680 | 4/20/2019 |
1.0.61 | 669 | 4/20/2019 |
1.0.58 | 663 | 4/17/2019 |
1.0.54 | 687 | 4/15/2019 |
1.0.51 | 1,047 | 4/14/2019 |
1.0.46 | 45,538 | 12/20/2018 |
1.0.45 | 2,631 | 12/20/2018 |
1.0.44 | 729 | 12/19/2018 |
1.0.43 | 737 | 12/19/2018 |
1.0.42 | 755 | 12/19/2018 |
1.0.34 | 736 | 12/19/2018 |
1.0.26 | 1,091 | 12/12/2018 |
1.0.15 | 837 | 12/5/2018 |
1.0.14 | 789 | 12/5/2018 |
1.0.12 | 13,183 | 12/4/2018 |
1.0.10 | 42,838 | 12/2/2018 |
1.0.8 | 1,386 | 12/2/2018 |
1.0.7 | 1,326 | 11/30/2018 |
1.0.6 | 1,515 | 11/29/2018 |
1.0.5 | 1,542 | 11/29/2018 |
1.0.4 | 1,639 | 11/28/2018 |
1.0.3 | 1,082 | 11/22/2018 |
1.0.2 | 766 | 11/22/2018 |
1.0.1 | 755 | 11/22/2018 |
1.0.0 | 829 | 11/21/2018 |
TypeSupport provides tools to give you more information about .Net types and factories for working with objects, collections, enums and more.