Skip to content

Commit ec5dde1

Browse files
committed
- Fix Lint
1 parent 2cdda97 commit ec5dde1

File tree

9 files changed

+71
-2
lines changed

9 files changed

+71
-2
lines changed

src/TurboMapper/IMapper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public interface IMapper
1515
/// <param name="source"></param>
1616
/// <returns></returns>
1717
TTarget Map<TSource, TTarget>(TSource source);
18+
1819
/// <summary>
1920
/// Maps a collection of objects of type TSource to a collection of objects of type TDestination.
2021
/// </summary>
@@ -23,6 +24,7 @@ public interface IMapper
2324
/// <param name="source"></param>
2425
/// <returns></returns>
2526
IEnumerable<TDestination> Map<TSource, TDestination>(IEnumerable<TSource> source);
27+
2628
/// <summary>
2729
/// Validates the mapping configuration between TSource and TTarget types.
2830
/// </summary>

src/TurboMapper/IMappingExpression.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ public interface IMappingExpression<TSource, TTarget>
1818
/// <param name="sourceMember"></param>
1919
/// <returns></returns>
2020
IMappingExpression<TSource, TTarget> ForMember<TValue>(Expression<Func<TTarget, TValue>> targetMember, Expression<Func<TSource, TValue>> sourceMember);
21+
2122
/// <summary>
2223
/// Ignores a specific member in the target type during the mapping process.
2324
/// </summary>
2425
/// <typeparam name="TValue"></typeparam>
2526
/// <param name="targetMember"></param>
2627
/// <returns></returns>
2728
IMappingExpression<TSource, TTarget> Ignore<TValue>(Expression<Func<TTarget, TValue>> targetMember);
29+
2830
/// <summary>
2931
/// Applies a condition to a specific member in the target type, determining whether it should be mapped based on the provided condition function.
3032
/// </summary>
@@ -33,6 +35,7 @@ public interface IMappingExpression<TSource, TTarget>
3335
/// <param name="condition"></param>
3436
/// <returns></returns>
3537
IMappingExpression<TSource, TTarget> When<TValue>(Expression<Func<TTarget, TValue>> targetMember, Func<TSource, bool> condition);
38+
3639
/// <summary>
3740
/// Maps a target member using a custom transformation function that takes a source value and produces a target value.
3841
/// </summary>

src/TurboMapper/IObjectMap.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal interface IObjectMap
1515
/// <typeparam name="TTarget"></typeparam>
1616
/// <param name="mappings"></param>
1717
void CreateMap<TSource, TTarget>(List<PropertyMapping> mappings = null);
18+
1819
/// <summary>
1920
/// Creates a mapping configuration between TSource and TTarget types with specified property mappings and an option to enable default mapping for unmapped properties.
2021
/// </summary>
@@ -23,6 +24,7 @@ internal interface IObjectMap
2324
/// <param name="mappings"></param>
2425
/// <param name="enableDefaultMapping"></param>
2526
void CreateMap<TSource, TTarget>(List<PropertyMapping> mappings, bool enableDefaultMapping);
27+
2628
/// <summary>
2729
/// Registers a custom converter function to convert from TSource to TDestination types.
2830
/// </summary>

src/TurboMapper/Impl/Mapper.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ internal class MapperConfiguration
1616
/// A list of custom property mappings defined for this configuration.
1717
/// </summary>
1818
public List<PropertyMapping> Mappings { get; set; }
19+
1920
/// <summary>
2021
/// Indicates whether default name-based mapping is enabled for properties not explicitly mapped.
2122
/// </summary>
2223
public bool EnableDefaultMapping { get; set; }
24+
2325
/// <summary>
2426
/// Initializes a new instance of the MapperConfiguration class with specified property mappings and default mapping setting.
2527
/// </summary>
@@ -31,6 +33,7 @@ public MapperConfiguration(List<PropertyMapping> mappings, bool enableDefaultMap
3133
EnableDefaultMapping = enableDefaultMapping;
3234
}
3335
}
36+
3437
/// <summary>
3538
/// Implements the object mapping functionality, allowing for configuration of mappings between source and target types, including support for custom property mappings, nested properties, conditional mapping, and transformation functions.
3639
/// </summary>
@@ -40,26 +43,32 @@ internal class Mapper : IMapper, IObjectMap
4043
/// Holds mapping configurations indexed by source type and target type.
4144
/// </summary>
4245
private readonly Dictionary<Type, Dictionary<Type, MapperConfiguration>> _configurations;
46+
4347
/// <summary>
4448
/// Caches property info arrays for types to optimize reflection performance.
4549
/// </summary>
4650
private readonly Dictionary<Type, System.Reflection.PropertyInfo[]> _propertyCache;
51+
4752
/// <summary>
4853
/// Caches property info for nested property paths to optimize reflection performance.
4954
/// </summary>
5055
private readonly Dictionary<string, System.Reflection.PropertyInfo> _propertyPathCache;
56+
5157
/// <summary>
5258
/// Caches factory functions for creating instances of types to optimize object creation performance.
5359
/// </summary>
5460
private readonly Dictionary<Type, Func<object>> _factoryCache;
61+
5562
/// <summary>
5663
/// Caches getter functions for properties to optimize property access performance.
5764
/// </summary>
5865
private readonly Dictionary<string, Func<object, object>> _getterCache;
66+
5967
/// <summary>
6068
/// Caches setter functions for properties to optimize property assignment performance.
6169
/// </summary>
6270
private readonly Dictionary<string, Action<object, object>> _setterCache;
71+
6372
/// <summary>
6473
/// Initializes a new instance of the Mapper class.
6574
/// </summary>
@@ -72,6 +81,7 @@ public Mapper()
7281
_getterCache = new Dictionary<string, Func<object, object>>();
7382
_setterCache = new Dictionary<string, Action<object, object>>();
7483
}
84+
7585
/// <summary>
7686
/// Creates a mapping configuration between TSource and TTarget types with optional property mappings.
7787
/// </summary>
@@ -88,6 +98,7 @@ public void CreateMap<TSource, TTarget>(List<PropertyMapping> mappings = null)
8898

8999
_configurations[sourceType][targetType] = new MapperConfiguration(mappings, true);
90100
}
101+
91102
/// <summary>
92103
/// Creates a mapping configuration between TSource and TTarget types with specified property mappings and an option to enable default mapping for unmapped properties.
93104
/// </summary>
@@ -105,6 +116,7 @@ public void CreateMap<TSource, TTarget>(List<PropertyMapping> mappings, bool ena
105116

106117
_configurations[sourceType][targetType] = new MapperConfiguration(mappings, enableDefaultMapping);
107118
}
119+
108120
/// <summary>
109121
/// Maps an instance of TSource to a new instance of TTarget, applying any configured property mappings, including support for nested properties, conditional mapping, and transformation functions.
110122
/// </summary>
@@ -136,6 +148,7 @@ public TTarget Map<TSource, TTarget>(TSource source)
136148

137149
return target;
138150
}
151+
139152
/// <summary>
140153
/// Tries to retrieve the mapping configuration for the specified source and target types.
141154
/// </summary>
@@ -194,6 +207,7 @@ internal void ApplyCustomMappings<TSource, TTarget>(
194207
// Then apply default name-based mapping for unmapped properties
195208
ApplyDefaultNameBasedMapping(source, target, mappings);
196209
}
210+
197211
/// <summary>
198212
/// Applies only custom mappings with default mapping disabled. Ignores properties marked as ignored and applies conditions if specified.
199213
/// </summary>
@@ -229,6 +243,7 @@ internal void ApplyCustomMappingsWithDefaultDisabled<TSource, TTarget>(
229243
}
230244
}
231245
}
246+
232247
/// <summary>
233248
/// Registers a custom converter function to convert from TSource to TDestination types.
234249
/// </summary>
@@ -240,6 +255,7 @@ public void RegisterConverter<TSource, TDestination>(Func<TSource, TDestination>
240255
var key = $"{typeof(TSource).FullName}_{typeof(TDestination).FullName}";
241256
_converters[key] = converter;
242257
}
258+
243259
/// <summary>
244260
/// Applies default name-based mapping for properties not explicitly mapped, ignoring any properties that are marked as ignored in custom mappings.
245261
/// </summary>
@@ -270,6 +286,7 @@ private void ApplyDefaultNameBasedMapping<TSource, TTarget>(
270286
}
271287
}
272288
}
289+
273290
/// <summary>
274291
/// Checks if a target property is explicitly targeted in custom mappings (not ignored).
275292
/// </summary>
@@ -281,6 +298,7 @@ private bool IsTargetedInCustomMappings(string targetPropertyName, List<Property
281298
return customMappings.Exists(m =>
282299
m.TargetPropertyPath.Split('.').Last() == targetPropertyName && !m.IsIgnored);
283300
}
301+
284302
/// <summary>
285303
/// Checks if a target property is marked as ignored in custom mappings.
286304
/// </summary>
@@ -297,6 +315,7 @@ private bool IsIgnoredInCustomMappings(string targetPropertyName, List<PropertyM
297315
/// Holds custom converters registered for specific source-target type pairs.
298316
/// </summary>
299317
private readonly Dictionary<string, Delegate> _converters = new Dictionary<string, Delegate>();
318+
300319
/// <summary>
301320
/// Creates an instance of the specified type using a cached factory function for performance.
302321
/// </summary>
@@ -340,6 +359,7 @@ public ValidationResult ValidateMapping<TSource, TTarget>()
340359
var isValid = errors.Count == 0;
341360
return new ValidationResult(isValid, errors);
342361
}
362+
343363
/// <summary>
344364
/// Checks if a property exists on a type, supporting nested properties using dot notation.
345365
/// </summary>
@@ -362,6 +382,7 @@ private bool PropertyExists(Type type, string propertyPath)
362382

363383
return true;
364384
}
385+
365386
/// <summary>
366387
/// Creates an instance of the specified type using a cached factory function for performance.
367388
/// </summary>
@@ -391,6 +412,7 @@ private bool TryConvertWithCustomConverter(object value, Type targetType, out ob
391412

392413
return false;
393414
}
415+
394416
/// <summary>
395417
/// Gets or creates a factory function for the specified type to optimize object creation.
396418
/// </summary>
@@ -414,6 +436,7 @@ internal void ApplyNameBasedMapping<TSource, TTarget>(TSource source, TTarget ta
414436
}
415437
}
416438
}
439+
417440
/// <summary>
418441
/// Processes the mapping of a single property from source to target, handling both simple and complex types, including nested objects.
419442
/// </summary>
@@ -443,6 +466,7 @@ private void ProcessPropertyMapping<TSource, TTarget>(
443466
HandleSimpleTypeMapping(sourceValue, target, targetProp, targetSetter);
444467
}
445468
}
469+
446470
/// <summary>
447471
/// Handles the mapping of complex type properties, creating nested target objects as needed and recursively applying name-based mapping.
448472
/// </summary>
@@ -472,6 +496,7 @@ private void HandleComplexTypeMapping<TSource, TTarget>(
472496
targetSetter?.Invoke(target, null);
473497
}
474498
}
499+
475500
/// <summary>
476501
/// Handles the mapping of simple type properties, applying type conversion as needed and gracefully handling conversion failures.
477502
/// </summary>
@@ -497,6 +522,7 @@ private void HandleSimpleTypeMapping<TTarget>(
497522
// This allows for graceful handling of incompatible types
498523
}
499524
}
525+
500526
/// <summary>
501527
/// Get or create nested object for complex type properties, creating the instance if it does not already exist.
502528
/// </summary>
@@ -519,6 +545,7 @@ private object GetOrCreateNestedObject<TTarget>(
519545
}
520546
return nestedTargetValue;
521547
}
548+
522549
/// <summary>
523550
/// Get nested property value using dot notation for property paths.
524551
/// </summary>
@@ -546,6 +573,7 @@ private object GetNestedValue(object obj, string propertyPath)
546573

547574
return currentObject;
548575
}
576+
549577
/// <summary>
550578
/// Set nested property value using dot notation for property paths, creating intermediate objects as needed.
551579
/// </summary>
@@ -588,6 +616,7 @@ private void SetNestedValue(object obj, string propertyPath, object value)
588616
setter(currentObject, convertedValue);
589617
}
590618
}
619+
591620
/// <summary>
592621
/// Is Complex Type (i.e., class but not string, array, or collection)
593622
/// </summary>
@@ -605,6 +634,7 @@ private bool IsComplexType(Type type)
605634
return false;
606635
return true;
607636
}
637+
608638
/// <summary>
609639
/// Checks if the specified type is a nullable type (e.g., Nullable<int>).
610640
/// </summary>
@@ -614,6 +644,7 @@ private bool IsNullableType(Type type)
614644
{
615645
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
616646
}
647+
617648
/// <summary>
618649
/// Convert value to the specified target type, handling nullable types, enums, and using custom converters if available.
619650
/// </summary>
@@ -802,6 +833,7 @@ private object ConvertValue(object value, Type targetType)
802833

803834
return value;
804835
}
836+
805837
/// <summary>
806838
/// Maps an object of unknown type to the specified target type using reflection to invoke the generic Map method.
807839
/// </summary>
@@ -824,6 +856,7 @@ private object Map(object source, Type targetType)
824856
var specificMapMethod = genericMapMethod.MakeGenericMethod(sourceType, targetType);
825857
return specificMapMethod.Invoke(this, new object[] { source });
826858
}
859+
827860
/// <summary>
828861
/// Gets the properties of a type, using a cache to optimize repeated access.
829862
/// </summary>
@@ -840,6 +873,7 @@ private System.Reflection.PropertyInfo[] GetTypeProperties(Type type)
840873
_propertyCache[type] = properties;
841874
return properties;
842875
}
876+
843877
/// <summary>
844878
/// Gets or creates a factory function for the specified type to optimize object creation.
845879
/// </summary>
@@ -869,6 +903,7 @@ private Func<object> GetOrCreateFactory(Type type)
869903
_factoryCache[type] = factory;
870904
return factory;
871905
}
906+
872907
/// <summary>
873908
/// Creates an instance of the specified type using a cached factory function for performance.
874909
/// </summary>
@@ -879,6 +914,7 @@ private object CreateInstance(Type type)
879914
var factory = GetOrCreateFactory(type);
880915
return factory();
881916
}
917+
882918
/// <summary>
883919
/// Gets or creates a getter function for the specified property of the given type, using a cache to optimize repeated access.
884920
/// </summary>
@@ -911,6 +947,7 @@ private Func<object, object> GetOrCreateGetter(Type objType, string propertyName
911947
_getterCache[cacheKey] = getter;
912948
return getter;
913949
}
950+
914951
/// <summary>
915952
/// Gets or creates a setter function for the specified property of the given type, using a cache to optimize repeated access.
916953
/// </summary>
@@ -946,6 +983,7 @@ private Action<object, object> GetOrCreateSetter(Type objType, string propertyNa
946983
_setterCache[cacheKey] = setter;
947984
return setter;
948985
}
986+
949987
/// <summary>
950988
/// Maps a source object of type TSource to a new instance of type TDestination using the configured mappings.
951989
/// </summary>

src/TurboMapper/MappingExpression.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public IMappingExpression<TSource, TTarget> ForMember<TValue>(
3939

4040
return this;
4141
}
42+
4243
/// <summary>
4344
/// Extracts the member path from a given expression for the target type, supporting nested properties.
4445
/// </summary>
@@ -49,6 +50,7 @@ private string GetMemberPathForTarget<TValue>(Expression<Func<TTarget, TValue>>
4950
{
5051
return GetMemberPathInternal(expression);
5152
}
53+
5254
/// <summary>
5355
/// Extracts the member path from a given expression for the source type, supporting nested properties.
5456
/// </summary>
@@ -59,6 +61,7 @@ private string GetMemberPathForSource<TValue>(Expression<Func<TSource, TValue>>
5961
{
6062
return GetMemberPathInternal(expression);
6163
}
64+
6265
/// <summary>
6366
/// Extracts the member path from a given expression, supporting nested properties.
6467
/// </summary>
@@ -86,6 +89,7 @@ private string GetLastPropertyName(string path)
8689
var parts = path.Split('.');
8790
return parts[parts.Length - 1];
8891
}
92+
8993
/// <summary>
9094
/// Ignores a specific member in the target type during the mapping process.
9195
/// </summary>
@@ -107,6 +111,7 @@ public IMappingExpression<TSource, TTarget> Ignore<TValue>(Expression<Func<TTarg
107111

108112
return this;
109113
}
114+
110115
/// <summary>
111116
/// Applies a condition to a specific member in the target type, determining whether it should be mapped based on the provided condition function.
112117
/// </summary>
@@ -129,6 +134,7 @@ public IMappingExpression<TSource, TTarget> When<TValue>(Expression<Func<TTarget
129134

130135
return this;
131136
}
137+
132138
/// <summary>
133139
/// Maps a target member using a custom transformation function that takes a source value and produces a target value.
134140
/// </summary>

0 commit comments

Comments
 (0)