Represents a pair of types used for object mapping and type conversion
$ dotnet add package StoneKit.Core.Structs.TypePairThe TypePair struct represents a pair of types, commonly used for object mapping and type conversion. It includes various properties and methods to facilitate type-related operations.
You can install by using NuGet:
PM> Install-Package StoneKit.Core.Structs.TypePair
var typePair = new TypePair(typeof(SourceType), typeof(TargetType));
var typePair = TypePair.Create<SourceType, TargetType>();
// Check if the types are both enums
bool isEnumTypes = typePair.IsEnumTypes;
// Check if the types are both enumerable
bool isEnumerableTypes = typePair.IsEnumerableTypes;
// Check if the source type is nullable while the target type is not
bool isNullableToNotNullable = typePair.IsNullableToNotNullable;
// Check if the types are deep cloneable
bool isDeepCloneable = typePair.IsDeepCloneable;
// Check if a TypeConverter is available for type conversion
bool hasTypeConverter = typePair.HasTypeConverter();
// Check if two TypePairs are equal
bool areEqual = typePair1.Equals(typePair2);
// Example: Creating TypePairs
var typePair1 = new TypePair(typeof(int), typeof(string));
var typePair2 = TypePair.Create<double, decimal>();
// Example: Checking Type Characteristics
bool isEnumTypes = typePair1.IsEnumTypes;
bool isDeepCloneable = typePair2.IsDeepCloneable;
// Example: Checking for Type Conversion
bool hasTypeConverter = typePair1.HasTypeConverter();
// Example: Equality Comparison
bool areEqual = typePair1.Equals(typePair2);
This project is licensed under the MIT License.
10.0K