diff --git a/src/Mapster.Async/TypeAdapterExtensions.cs b/src/Mapster.Async/TypeAdapterExtensions.cs index 5ace867c..b42a754e 100644 --- a/src/Mapster.Async/TypeAdapterExtensions.cs +++ b/src/Mapster.Async/TypeAdapterExtensions.cs @@ -13,7 +13,16 @@ internal static U GetValueOrDefault(this IDictionary dict, T key) return dict.TryGetValue(key, out var value) ? value : default; } - public static TypeAdapterSetter AfterMappingAsync( + + /// + /// Setup async operation + /// + /// + /// + /// + /// + /// + public static TypeAdapterSetter AfterMappingAsync( this TypeAdapterSetter setter, Func action) { setter.AfterMapping(dest => @@ -27,7 +36,17 @@ public static TypeAdapterSetter AfterMappingAsync( return setter; } - public static TypeAdapterSetter AfterMappingAsync( + + /// + /// Setup async operation + /// + /// + /// + /// + /// + /// + /// + public static TypeAdapterSetter AfterMappingAsync( this TypeAdapterSetter setter, Func action) { setter.AfterMapping((src, dest) => @@ -41,7 +60,14 @@ public static TypeAdapterSetter AfterMappingAsync AdaptToTypeAsync(this IAdapterBuilder builder) + + /// + /// Map asynchronously to destination type. + /// + /// Destination type to map. + /// + /// Type of destination object that mapped. + public static async Task AdaptToTypeAsync(this IAdapterBuilder builder) { var tasks = new List(); builder.Parameters[ASYNC_KEY] = tasks; @@ -54,7 +80,15 @@ public static async Task AdaptToTypeAsync(this IAdap } } - public static async Task AdaptToAsync(this IAdapterBuilder builder, TDestination destination) + + /// + /// Map asynchronously to destination type. + /// + /// Destination type to map. + /// + /// Destination object to map. + /// Type of destination object that mapped. + public static async Task AdaptToAsync(this IAdapterBuilder builder, TDestination destination) { var tasks = new List(); builder.Parameters[ASYNC_KEY] = tasks; diff --git a/src/Mapster.Core/Register/AdaptAttributeBuilder.cs b/src/Mapster.Core/Register/AdaptAttributeBuilder.cs index 93a85de1..6797700c 100644 --- a/src/Mapster.Core/Register/AdaptAttributeBuilder.cs +++ b/src/Mapster.Core/Register/AdaptAttributeBuilder.cs @@ -16,7 +16,12 @@ public AdaptAttributeBuilder(BaseAdaptAttribute attribute) this.Attribute = attribute; } - public AdaptAttributeBuilder ForTypes(params Type[] types) + /// + /// Configures the builder for specific types. + /// + /// Types to configure. + /// + public AdaptAttributeBuilder ForTypes(params Type[] types) { foreach (var type in types) { @@ -27,7 +32,14 @@ public AdaptAttributeBuilder ForTypes(params Type[] types) return this; } - public AdaptAttributeBuilder ForAllTypesInNamespace(Assembly assembly, string @namespace) + + /// + /// Configures the builder for all types in a given namespace within an assembly. + /// + /// The assembly containing the types. + /// The namespace of the types to include. + /// + public AdaptAttributeBuilder ForAllTypesInNamespace(Assembly assembly, string @namespace) { foreach (var type in assembly.GetTypes()) { @@ -40,7 +52,14 @@ public AdaptAttributeBuilder ForAllTypesInNamespace(Assembly assembly, string @n return this; } - public AdaptAttributeBuilder ForType(Action>? propertyConfig = null) + + /// + /// Configures the builder for a specific type and allows for property-specific configuration. + /// + /// + /// An optional action for configuring properties of the specified type. + /// + public AdaptAttributeBuilder ForType(Action>? propertyConfig = null) { if (!this.TypeSettings.TryGetValue(typeof(T), out var settings)) { @@ -52,7 +71,13 @@ public AdaptAttributeBuilder ForType(Action>? prope return this; } - public AdaptAttributeBuilder ExcludeTypes(params Type[] types) + + /// + /// Excludes specific types from the configuration. + /// + /// An array of types to exclude. + /// + public AdaptAttributeBuilder ExcludeTypes(params Type[] types) { foreach (var type in types) { @@ -62,7 +87,13 @@ public AdaptAttributeBuilder ExcludeTypes(params Type[] types) return this; } - public AdaptAttributeBuilder ExcludeTypes(Func predicate) + + /// + /// Exclude certain types from the adaptation process based on a provided predicate. + /// + /// Predicate function should evaluate to true for types that you want to exclude from the mapping and false for types that should not be excluded. + /// + public AdaptAttributeBuilder ExcludeTypes(Func predicate) { foreach (var type in this.TypeSettings.Keys.ToList()) { @@ -73,67 +104,135 @@ public AdaptAttributeBuilder ExcludeTypes(Func predicate) return this; } - public AdaptAttributeBuilder IgnoreAttributes(params Type[] attributes) + + /// + /// Specifies attributes to ignore during mapping. + /// + /// An array of attributes to ignore. + /// + public AdaptAttributeBuilder IgnoreAttributes(params Type[] attributes) { this.Attribute.IgnoreAttributes = attributes; return this; } - public AdaptAttributeBuilder IgnoreNoAttributes(params Type[] attributes) + + /// + /// Specifies attributes that should not be ignored during mapping. + /// + /// An array of attributes that should not be ignored. + /// + public AdaptAttributeBuilder IgnoreNoAttributes(params Type[] attributes) { this.Attribute.IgnoreNoAttributes = attributes; return this; } - public AdaptAttributeBuilder IgnoreNamespaces(params string[] namespaces) + + /// + /// Specifies namespaces to ignore during mapping. + /// + /// An array of namespaces to ignore. + /// + public AdaptAttributeBuilder IgnoreNamespaces(params string[] namespaces) { this.Attribute.IgnoreNamespaces = namespaces; return this; } - public AdaptAttributeBuilder IgnoreNullValues(bool value) + + /// + /// Configures whether null values should be ignored during mapping. + /// + /// A boolean value indicating whether to ignore null values. + /// + public AdaptAttributeBuilder IgnoreNullValues(bool value) { this.Attribute.IgnoreNullValues = value; return this; } - public AdaptAttributeBuilder RequireDestinationMemberSource(bool value) + + /// + /// Configures whether a destination member source is required during. + /// + /// A boolean value indicating whether a destination member source is required. + /// + public AdaptAttributeBuilder RequireDestinationMemberSource(bool value) { this.Attribute.RequireDestinationMemberSource = value; return this; } - public AdaptAttributeBuilder MapToConstructor(bool value) + + /// + /// Configures whether mapping should be performed to constructors. + /// + /// A boolean value indicating whether mapping to constructors is enabled. + /// + public AdaptAttributeBuilder MapToConstructor(bool value) { this.Attribute.MapToConstructor = value; return this; } - public AdaptAttributeBuilder MaxDepth(int depth) + + /// + /// Sets the maximum depth for mapping. + /// + /// The maximum depth for mapping. + /// + public AdaptAttributeBuilder MaxDepth(int depth) { this.Attribute.MaxDepth = depth; return this; } - - public AdaptAttributeBuilder PreserveReference(bool value) + + + /// + /// Configures whether to preserve object references during mapping. + /// + /// A boolean value indicating whether to preserve object references. + /// + public AdaptAttributeBuilder PreserveReference(bool value) { this.Attribute.PreserveReference = value; return this; } - - public AdaptAttributeBuilder ShallowCopyForSameType(bool value) + + + /// + /// Configures whether to perform a shallow copy for the same source and destination type. + /// + /// A boolean value indicating whether to perform a shallow copy. + /// + public AdaptAttributeBuilder ShallowCopyForSameType(bool value) { this.Attribute.ShallowCopyForSameType = value; return this; } - public AdaptAttributeBuilder AlterType() + + /// + /// Forward property types. + /// + /// Forward property from type. + /// Forward property to type. + /// + public AdaptAttributeBuilder AlterType() { this.AlterTypes.Add(type => type == typeof(TFrom) ? typeof(TTo) : null); return this; } - public AdaptAttributeBuilder AlterType(Func predicate, Type toType) + + /// + /// Forward property types for Code generation. + /// + /// A function that takes a Type as input and returns a Boolean value. This function is used to evaluate whether the forward property should be applied to the target type. If the predicate returns true, the target type will be replaced; otherwise, it remains unchanged. + /// Type of destination to forward property type. + /// + public AdaptAttributeBuilder AlterType(Func predicate, Type toType) { this.AlterTypes.Add(type => predicate(type) ? toType : null); return this; diff --git a/src/Mapster.Core/Register/PropertySettingBuilder.cs b/src/Mapster.Core/Register/PropertySettingBuilder.cs index 03d10634..69b35b1c 100644 --- a/src/Mapster.Core/Register/PropertySettingBuilder.cs +++ b/src/Mapster.Core/Register/PropertySettingBuilder.cs @@ -23,21 +23,45 @@ private PropertySetting ForProperty(string name) return setting; } - public PropertySettingBuilder Ignore(Expression> member) + + /// + /// Ignore a specific property during mapping. + /// + /// + /// A lambda expression that identifies the property to be ignored during mapping. + /// + public PropertySettingBuilder Ignore(Expression> member) { var setting = ForProperty(member.GetMemberName()); setting.Ignore = true; return this; } - public PropertySettingBuilder Map(Expression> member, string targetPropertyName) + + /// + /// Map a specific property of the source type to a target property with a different name during mapping. + /// + /// + /// A lambda expression that identifies the source property to be mapped. + /// The name of the target property to which the source property should be mapped during the mapping process. + /// + public PropertySettingBuilder Map(Expression> member, string targetPropertyName) { var setting = ForProperty(member.GetMemberName()); setting.TargetPropertyName = targetPropertyName; return this; } - public PropertySettingBuilder Map(Expression> member, Type targetPropertyType, string? targetPropertyName = null) + + /// + /// Map a specific property of the source type to a target property with a different type and name during mapping. + /// + /// + /// A lambda expression that identifies the source property to be mapped. + /// The type of the target property to which the source property should be mapped during the mapping process. + /// The name of the target property to which the source property should be mapped. + /// + public PropertySettingBuilder Map(Expression> member, Type targetPropertyType, string? targetPropertyName = null) { var setting = ForProperty(member.GetMemberName()); setting.TargetPropertyType = targetPropertyType; @@ -45,7 +69,17 @@ public PropertySettingBuilder Map(Expression> membe return this; } - public PropertySettingBuilder Map(Expression> member, Expression> mapFunc, string? targetPropertyName = null) + + /// + /// Map a specific property of the source type to a target property using a custom mapping function. + /// + /// Type of source property. + /// Type of target property type. + /// A lambda expression that identifies the source property to be mapped. + /// A lambda expression that defines the custom mapping function. + /// The name of the target property to which the source property should be mapped. + /// + public PropertySettingBuilder Map(Expression> member, Expression> mapFunc, string? targetPropertyName = null) { var setting = ForProperty(member.GetMemberName()); setting.MapFunc = mapFunc; diff --git a/src/Mapster.DependencyInjection/ServiceMapper.cs b/src/Mapster.DependencyInjection/ServiceMapper.cs index 03c8fc3d..1d909893 100644 --- a/src/Mapster.DependencyInjection/ServiceMapper.cs +++ b/src/Mapster.DependencyInjection/ServiceMapper.cs @@ -13,41 +13,88 @@ public ServiceMapper(IServiceProvider serviceProvider, TypeAdapterConfig config) _serviceProvider = serviceProvider; } - public override ITypeAdapterBuilder From(TSource source) + /// + /// Create mapping builder. + /// + /// Source type to create mapping builder. + /// Source object to create mapping builder. + /// + public override ITypeAdapterBuilder From(TSource source) { return base.From(source) .AddParameters(DI_KEY, _serviceProvider); } - public override TDestination Map(object source) + + /// + /// Perform mapping from source object to type of destination. + /// + /// Destination type to create mapping builder. + /// Source object to create mapping builder. + /// Type of destination object that mapped. + public override TDestination Map(object source) { using var scope = new MapContextScope(); scope.Context.Parameters[DI_KEY] = _serviceProvider; return base.Map(source); } - public override TDestination Map(TSource source) + + /// + /// Perform mapping from type of source to type of destination. + /// + /// Source type to map. + /// Destination type to map. + /// Source object to map. + /// Type of destination object that mapped. + public override TDestination Map(TSource source) { using var scope = new MapContextScope(); scope.Context.Parameters[DI_KEY] = _serviceProvider; return base.Map(source); } - public override TDestination Map(TSource source, TDestination destination) + + /// + /// Perform mapping from type of source to type of destination. + /// + /// Source type to map. + /// Destination type to map. + /// Source object to map. + /// Destination object to map. + /// Type of destination object that mapped. + public override TDestination Map(TSource source, TDestination destination) { using var scope = new MapContextScope(); scope.Context.Parameters[DI_KEY] = _serviceProvider; return base.Map(source, destination); } - public override object Map(object source, Type sourceType, Type destinationType) + + /// + /// Perform mapping source object from source type to destination type. + /// + /// Source object to map. + /// Source type to map. + /// Destination type to map. + /// Mapped object. + public override object Map(object source, Type sourceType, Type destinationType) { using var scope = new MapContextScope(); scope.Context.Parameters[DI_KEY] = _serviceProvider; return base.Map(source, sourceType, destinationType); } - public override object Map(object source, object destination, Type sourceType, Type destinationType) + + /// + /// Perform mapping source object from source type to destination type. + /// + /// Source object to map. + /// Destination object to map. + /// Source type to map. + /// Destination type to map. + /// + public override object Map(object source, object destination, Type sourceType, Type destinationType) { using var scope = new MapContextScope(); scope.Context.Parameters[DI_KEY] = _serviceProvider; diff --git a/src/Mapster.EFCore/TypeAdapterBuilderExtensions.cs b/src/Mapster.EFCore/TypeAdapterBuilderExtensions.cs index 11fa744d..3ab0cb5b 100644 --- a/src/Mapster.EFCore/TypeAdapterBuilderExtensions.cs +++ b/src/Mapster.EFCore/TypeAdapterBuilderExtensions.cs @@ -80,7 +80,14 @@ public static ITypeAdapterBuilder EntityFromContext(this IType }, context.GetType().FullName); } - public static IQueryable ProjectToType(this IAdapterBuilder source) + + /// + /// Mapping from queryable. + /// + /// Type of destination. + /// Source object to adopt. + /// + public static IQueryable ProjectToType(this IAdapterBuilder source) { var queryable = source.Source.ProjectToType(source.Config); if (!source.HasParameter || source.Parameters.All(it => it.Key.StartsWith("Mapster."))) diff --git a/src/Mapster/Interfaces/IMapper.cs b/src/Mapster/Interfaces/IMapper.cs index f32b4b51..201420b0 100644 --- a/src/Mapster/Interfaces/IMapper.cs +++ b/src/Mapster/Interfaces/IMapper.cs @@ -7,11 +7,65 @@ namespace MapsterMapper public interface IMapper { TypeAdapterConfig Config { get; } - ITypeAdapterBuilder From(TSource source); - TDestination Map(object source); - TDestination Map(TSource source); - TDestination Map(TSource source, TDestination destination); - object Map(object source, Type sourceType, Type destinationType); - object Map(object source, object destination, Type sourceType, Type destinationType); + + + /// + /// Create mapping builder. + /// + /// Source type to create mapping builder. + /// Source object to create mapping builder. + /// Adapter builder type. + ITypeAdapterBuilder From(TSource source); + + + /// + /// Perform mapping from source object to type of destination. + /// + /// Destination type to create mapping builder. + /// Source object to create mapping builder. + /// Type of destination object that mapped. + TDestination Map(object source); + + + /// + /// Perform mapping from type of source to type of destination. + /// + /// Source type to map. + /// Destination type to map. + /// Source object to map. + /// Type of destination object that mapped. + TDestination Map(TSource source); + + + /// + /// Perform mapping from type of source to type of destination. + /// + /// Source type to map. + /// Destination type to map. + /// Source object to map. + /// Destination object to map. + /// Type of destination object that mapped. + TDestination Map(TSource source, TDestination destination); + + + /// + /// Perform mapping source object from source type to destination type. + /// + /// Source object to map. + /// Source type to map. + /// Destination type to map. + /// Mapped object. + object Map(object source, Type sourceType, Type destinationType); + + + /// + /// Perform mapping source object from source type to destination type. + /// + /// Source object to map. + /// Destination object to map. + /// Source type to map. + /// Destination type to map. + /// Mapped object. + object Map(object source, object destination, Type sourceType, Type destinationType); } } diff --git a/src/Mapster/Mapper.cs b/src/Mapster/Mapper.cs index d63f6213..2694c7f3 100644 --- a/src/Mapster/Mapper.cs +++ b/src/Mapster/Mapper.cs @@ -16,12 +16,25 @@ public Mapper(TypeAdapterConfig config) Config = config; } - public virtual ITypeAdapterBuilder From(TSource source) + /// + /// Create mapping builder. + /// + /// Source type to create mapping builder. + /// + /// + public virtual ITypeAdapterBuilder From(TSource source) { return TypeAdapter.BuildAdapter(source, Config); } - public virtual TDestination Map(object source) + + /// + /// Perform mapping source object to type of destination. + /// + /// Destination type to perform mapping + /// Source object to perform mapping. + /// type of destination mapping result. + public virtual TDestination Map(object source) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (source == null) @@ -31,18 +44,43 @@ public virtual TDestination Map(object source) return fn(source); } - public virtual TDestination Map(TSource source) + + /// + /// Perform mapping from type of source to type of destination. + /// + /// Source type to map. + /// Destination type to map. + /// + /// type of destination mapping result + public virtual TDestination Map(TSource source) { var fn = Config.GetMapFunction(); return fn(source); } - public virtual TDestination Map(TSource source, TDestination destination) + + /// + /// Perform mapping from type of source to type of destination. + /// + /// Source type to map. + /// Destination type to map. + /// Source object to map. + /// Destination type to map. + /// type of destination mapping result + public virtual TDestination Map(TSource source, TDestination destination) { var fn = Config.GetMapToTargetFunction(); return fn(source, destination); } + + /// + /// Perform mapping source object from source type to destination type. + /// + /// Source object to map. + /// Source type to map. + /// Destination type to map. + /// mapped result object public virtual object Map(object source, Type sourceType, Type destinationType) { var del = Config.GetMapFunction(sourceType, destinationType); @@ -59,7 +97,16 @@ public virtual object Map(object source, Type sourceType, Type destinationType) } } - public virtual object Map(object source, object destination, Type sourceType, Type destinationType) + + /// + /// Perform mapping source object to destination object from source type to destination type. + /// + /// Source object to map. + /// Destination object to map. + /// Source type to map. + /// Destination type to map. + /// mapped result object + public virtual object Map(object source, object destination, Type sourceType, Type destinationType) { var del = Config.GetMapToTargetFunction(sourceType, destinationType); if (sourceType.GetTypeInfo().IsVisible && destinationType.GetTypeInfo().IsVisible) diff --git a/src/Mapster/TypeAdapterBuilder.cs b/src/Mapster/TypeAdapterBuilder.cs index 30c76880..26f93efa 100644 --- a/src/Mapster/TypeAdapterBuilder.cs +++ b/src/Mapster/TypeAdapterBuilder.cs @@ -25,7 +25,15 @@ internal TypeAdapterBuilder(TSource source, TypeAdapterConfig config) Config = config; } - [SuppressMessage("ReSharper", "ExplicitCallerInfoArgument")] + + /// + /// Allow you to keep config and mapping inline. + /// + /// + /// + /// + /// + [SuppressMessage("ReSharper", "ExplicitCallerInfoArgument")] public ITypeAdapterBuilder ForkConfig(Action action, #if !NET40 [CallerFilePath] @@ -40,7 +48,14 @@ public ITypeAdapterBuilder ForkConfig(Action action, return this; } - public ITypeAdapterBuilder AddParameters(string name, object value) + + /// + /// Passing runtime value. + /// + /// Parameter name. + /// Parameter value + /// + public ITypeAdapterBuilder AddParameters(string name, object value) { Parameters.Add(name, value); return this; @@ -58,9 +73,14 @@ private MapContextScope CreateMapContextScope() return scope; } - MapContextScope IAdapterBuilder.CreateMapContextScope() => CreateMapContextScope(); - public TDestination AdaptToType() + MapContextScope IAdapterBuilder.CreateMapContextScope() => CreateMapContextScope(); + /// + /// Mapping to new type using in adapter builder scenario. + /// + /// Destination type to adopt. + /// + public TDestination AdaptToType() { if (_parameters == null) return Map(); @@ -71,13 +91,26 @@ public TDestination AdaptToType() } } - private TDestination Map() + + /// + /// Perform mapping to type of destination in adapter builder scenario. + /// + /// Destination type to map. + /// + private TDestination Map() { var fn = Config.GetMapFunction(); return fn(Source); } - public TDestination AdaptTo(TDestination destination) + + /// + /// Mapping to existing object in adapter builder scenario. + /// + /// Destination type to adopt. + /// + /// + public TDestination AdaptTo(TDestination destination) { if (_parameters == null) return MapToTarget(destination); @@ -94,19 +127,37 @@ private TDestination MapToTarget(TDestination destination) return fn(Source, destination); } - public Expression> CreateMapExpression() + + /// + /// Get mapping expression. + /// + /// Destination type to create map expression. + /// + public Expression> CreateMapExpression() { var tuple = new TypeTuple(typeof(TSource), typeof(TDestination)); return (Expression>) Config.CreateMapExpression(tuple, MapType.Map); } - public Expression> CreateMapToTargetExpression() + + /// + /// Get mapping to existing object expression. + /// + /// Destination type to create map to target expression. + /// + public Expression> CreateMapToTargetExpression() { var tuple = new TypeTuple(typeof(TSource), typeof(TDestination)); return (Expression>) Config.CreateMapExpression(tuple, MapType.MapToTarget); } - public Expression> CreateProjectionExpression() + + /// + /// Get mapping from queryable expression. + /// + /// Destination type to create projection expression. + /// + public Expression> CreateProjectionExpression() { var tuple = new TypeTuple(typeof(TSource), typeof(TDestination)); return (Expression>) Config.CreateMapExpression(tuple, MapType.Projection); diff --git a/src/Mapster/TypeAdapterConfig.cs b/src/Mapster/TypeAdapterConfig.cs index 47de4086..f5ebbb3a 100644 --- a/src/Mapster/TypeAdapterConfig.cs +++ b/src/Mapster/TypeAdapterConfig.cs @@ -103,7 +103,13 @@ public TypeAdapterConfig() }); } - public TypeAdapterSetter When(Func canMap) + + /// + /// allows you to specify conditions for when a mapping should occur based on source and destination types and the mapping type. + /// + /// + /// + public TypeAdapterSetter When(Func canMap) { var rule = new TypeAdapterRule { @@ -114,7 +120,13 @@ public TypeAdapterSetter When(Func canMap) return new TypeAdapterSetter(rule.Settings, this); } - public TypeAdapterSetter When(Func canMap) + + /// + /// allows you to specify conditions for when a mapping should occur based on PreCompileArgument delegate + /// + /// + /// + public TypeAdapterSetter When(Func canMap) { var rule = new TypeAdapterRule { @@ -125,40 +137,80 @@ public TypeAdapterSetter When(Func canMap) return new TypeAdapterSetter(rule.Settings, this); } - public TypeAdapterSetter NewConfig() + + /// + /// Creates a new configuration for mapping between source and destination types. + /// + /// Source type. + /// Destination type. + /// + public TypeAdapterSetter NewConfig() { Remove(typeof(TSource), typeof(TDestination)); return ForType(); } - public TypeAdapterSetter NewConfig(Type sourceType, Type destinationType) + + /// + /// Creates a new configuration for mapping between source and destination types. + /// + /// Source type to create new configuration. + /// Destination type to create new configuration. + /// + public TypeAdapterSetter NewConfig(Type sourceType, Type destinationType) { Remove(sourceType, destinationType); return ForType(sourceType, destinationType); } - public TypeAdapterSetter ForType() + + /// + /// Configures a mapping for a specific source and destination type pair. + /// + /// + /// + /// + public TypeAdapterSetter ForType() { var key = new TypeTuple(typeof(TSource), typeof(TDestination)); var settings = GetSettings(key); return new TypeAdapterSetter(settings, this); } - public TypeAdapterSetter ForType(Type sourceType, Type destinationType) + + /// + /// Configures a mapping for a specific source and destination type pair. + /// + /// + /// + /// + public TypeAdapterSetter ForType(Type sourceType, Type destinationType) { var key = new TypeTuple(sourceType, destinationType); var settings = GetSettings(key); return new TypeAdapterSetter(settings, this); } - public TypeAdapterSetter ForDestinationType() + + /// + /// Configures a mapping for a specific destination type. + /// + /// Destination type. + /// + public TypeAdapterSetter ForDestinationType() { var key = new TypeTuple(typeof(void), typeof(TDestination)); var settings = GetSettings(key); return new TypeAdapterSetter(settings, this); } - public TypeAdapterSetter ForDestinationType(Type destinationType) + + /// + /// Configures a mapping for a specific destination type. + /// + /// Destination type. + /// + public TypeAdapterSetter ForDestinationType(Type destinationType) { var key = new TypeTuple(typeof(void), destinationType); var settings = GetSettings(key); @@ -582,7 +634,13 @@ private CompileArgument GetCompileArgument(TypeTuple tuple, MapType mapType, Com }; } - public void Compile(bool failFast = true) + + /// + /// Validates and cache mapping instructions. + /// + /// A boolean parameter that determines whether exceptions should be thrown immediately when mapping errors occur or whether to collect and aggregate them. The default value is true. + /// + public void Compile(bool failFast = true) { var exceptions = new List(); var keys = RuleMap.Keys.ToList(); @@ -614,7 +672,13 @@ public void Compile(bool failFast = true) } } - public void Compile(Type sourceType, Type destinationType) + + /// + /// Validates and cache mapping instructions. + /// + /// Source type to compile. + /// Destination type to compile. + public void Compile(Type sourceType, Type destinationType) { var tuple = new TypeTuple(sourceType, destinationType); _mapDict[tuple] = Compiler(CreateMapExpression(tuple, MapType.Map)); @@ -626,7 +690,11 @@ public void Compile(Type sourceType, Type destinationType) } } - public void CompileProjection() + + /// + /// Validates and cache mapping instructions for queryable. + /// + public void CompileProjection() { var keys = RuleMap.Keys.ToList(); foreach (var key in keys) @@ -635,13 +703,25 @@ public void CompileProjection() } } - public void CompileProjection(Type sourceType, Type destinationType) + + /// + /// Validates and cache mapping instructions for queryable. + /// + /// Source type to compile. + /// Destination type to compile. + public void CompileProjection(Type sourceType, Type destinationType) { var tuple = new TypeTuple(sourceType, destinationType); _projectionDict[tuple] = CreateProjectionCallExpression(tuple); } - public IList Scan(params Assembly[] assemblies) + + /// + /// Scans and registers mappings from specified assemblies. + /// + /// assemblies to scan. + /// A list of registered mappings + public IList Scan(params Assembly[] assemblies) { List registers = assemblies.Select(assembly => assembly.GetLoadableTypes() .Where(x => typeof(IRegister).GetTypeInfo().IsAssignableFrom(x.GetTypeInfo()) && x.GetTypeInfo().IsClass && !x.GetTypeInfo().IsAbstract)) @@ -652,12 +732,22 @@ public IList Scan(params Assembly[] assemblies) return registers; } - public void Apply(IEnumerable> registers) + + /// + /// Applies type mappings. + /// + /// collection of IRegister interface to apply mapping. + public void Apply(IEnumerable> registers) { Apply(registers.Select(register => register.Value)); } - public void Apply(IEnumerable registers) + + /// + /// Applies type mappings. + /// + /// collection of IRegister interface to apply mapping. + public void Apply(IEnumerable registers) { foreach (IRegister register in registers) { @@ -665,7 +755,12 @@ public void Apply(IEnumerable registers) } } - public void Apply(params IRegister[] registers) + + /// + /// Applies type mappings. + /// + /// IRegister interface params to apply mapping. + public void Apply(params IRegister[] registers) { foreach (IRegister register in registers) { @@ -673,7 +768,11 @@ public void Apply(params IRegister[] registers) } } - internal void Clear() + + /// + /// Clears all type mapping rules and settings + /// + internal void Clear() { var keys = RuleMap.Keys.ToList(); foreach (var key in keys) @@ -682,7 +781,13 @@ internal void Clear() } } - internal void Remove(Type sourceType, Type destinationType) + + /// + /// Removes a specific type mapping rule. + /// + /// Source type to remove. + /// Destination type to remove. + internal void Remove(Type sourceType, Type destinationType) { var key = new TypeTuple(sourceType, destinationType); Remove(key); @@ -706,7 +811,13 @@ private void Remove(TypeTuple key) .MapWith(src => src.Clone(), true); return config; }); - public TypeAdapterConfig Clone() + + + /// + /// Clones the current TypeAdapterConfig. + /// + /// + public TypeAdapterConfig Clone() { var fn = _cloneConfig.Value.GetMapFunction(); return fn(this); @@ -737,17 +848,30 @@ public TypeAdapterConfig Fork(Action action, public static class TypeAdapterConfig { - public static TypeAdapterSetter NewConfig() + /// + /// Creates a new configuration for mapping between the source and destination types. + /// + /// + public static TypeAdapterSetter NewConfig() { return TypeAdapterConfig.GlobalSettings.NewConfig(); } - public static TypeAdapterSetter ForType() + + /// + /// Creates a configuration for mapping between the source and destination types. + /// + /// + public static TypeAdapterSetter ForType() { return TypeAdapterConfig.GlobalSettings.ForType(); } - public static void Clear() + + /// + /// Clears the type mapping configuration for the specified source and destination types. + /// + public static void Clear() { TypeAdapterConfig.GlobalSettings.Remove(typeof(TSource), typeof(TDestination)); }