ShadowCaster is a lightweight and dynamic object-to-object mapper designed to map data between types seamlessly using reflection. It supports flexible mapping strategies and customizable property transformations.
🔄 Dynamic Object Mapping: Easily map properties from one object to another.
🏷️ Case-Sensitive Property Mapping: Transform property names to uppercase, lowercase, or leave them unchanged.
🛠️ Flexible Mapping Strategies:
ByProp: Direct object property-to-property mapping.
KeyValue: Property mapping from a key-value dictionary.
Just clone or include the ShadowCaster class in your project. No external dependencies are required.
var tiger = new Tiger("Simba", 3, "Yellow");
var caster = new Caster();
var lion = caster.AsDestination<Lion>(tiger, ShadowType.ByProp);
Console.WriteLine($"Lion Name: {lion.Name}, Age: {lion.Age}, Color: {lion.Color}");
var sourceDict = new Dictionary<string, object?>
{
{ "Name", "Simba" },
{ "Age", 3 },
{ "Color", "Yellow" }
};
var caster = new Caster();
var lion = caster.AsDestination<Lion>(sourceDict, ShadowType.KeyValue);
Console.WriteLine($"Lion Name: {lion.Name}, Age: {lion.Age}, Color: {lion.Color}");
🔹 Caster.AsDestination<TDestination>()
Executes the mapping process from the source object to create a new instance of the destination type.
Parameters
source (object): Source object to map from.
shadowType (ShadowType, optional): Mapping strategy. Default is ByProp.
characterCasing (CharacterCasing, optional): Specifies character casing rules (Normal, Lower, or Upper). Default is Normal.
Returns
Mapped destination object of type TDestination.
🔹 ShadowType Defines mapping strategies:
ByProp: Maps properties between objects.
KeyValue: Maps properties from a key-value dictionary.
🔹CharacterCasing Defines character casing rules:
Normal: Keeps property names unchanged.
Lower: Converts property names to lowercase.
Upper: Converts property names to uppercase.
Throws InvalidOperationException for unsupported source types.
Throws InvalidCastException when the source object is null or incompatible.
Feel free to submit issues or create pull requests to enhance ShadowCaster.
