/// <summary> /// Creates a new <see cref="MapTester{TSource, TDestination}"/> instance and initializes it /// to automatically test properties that have the same name on the "from" and "to" /// <typeparamref name="TSource"/> and <typeparamref name="TDestination"/> types. /// </summary> /// <remarks> /// This constructor is called by the "factory" /// <see cref="MapTester.ForMap{TSource, TDestination}"/> method. /// </remarks> internal MapTester() { Type sourceType = typeof(TSource); TypeInfo sourceTypeInfo = sourceType.GetTypeInfo(); Type destType = typeof(TDestination); TypeInfo destTypeInfo = destType.GetTypeInfo(); _memberTesters = new Dictionary <string, MapMemberTester <TSource, TDestination> >(); _destProperties = PropertyEnumerator.GetPublicInstanceReadWriteProperties(destTypeInfo); PropertyInfo[] srcProperties = PropertyEnumerator.GetPublicInstanceReadProperties(sourceTypeInfo); Tuple <string, string>[] commonPropertyNames = srcProperties .Join(_destProperties, src => src.Name.ToLowerInvariant(), dest => dest.Name.ToLowerInvariant(), (src, dest) => Tuple.Create(src.Name, dest.Name)) .ToArray(); foreach (Tuple <string, string> item in commonPropertyNames) { string sourcePropertyName = item.Item1; string propertyName = item.Item2; PropertyInfo srcProperty = PropertyInfoResolver.Resolve(sourceTypeInfo, sourcePropertyName); PropertyInfo destProperty = PropertyInfoResolver.Resolve(destTypeInfo, propertyName); SetTesterForProperty(propertyName, new MapMemberTester <TSource, TDestination>( this, dest => destProperty.GetValue(dest, null), src => srcProperty.GetValue(src, null))); } }
/// <summary> /// Creates a new <see cref="MapTester{TSource, TDestination}"/> instance and initializes it /// to automatically test properties that have the same name on the "from" and "to" /// <typeparamref name="TSource"/> and <typeparamref name="TDestination"/> types. /// </summary> /// <remarks> /// This constructor is called by the "factory" /// <see cref="MapTester.ForMap{TSource, TDestination}"/> method. /// </remarks> internal MapTester() { Type sourceType = typeof(TSource); TypeInfo sourceTypeInfo = sourceType.GetTypeInfo(); Type destType = typeof(TDestination); TypeInfo destTypeInfo = destType.GetTypeInfo(); _memberTesters = new Dictionary <string, MapMemberTester <TSource, TDestination> >(); _destProperties = PropertyEnumerator.GetPublicInstanceReadWriteProperties(destTypeInfo); PropertyInfo[] srcProperties = PropertyEnumerator.GetPublicInstanceReadWriteProperties(sourceTypeInfo); string[] commonPropertyNames = srcProperties .Join(_destProperties, dest => dest.Name, src => src.Name, (dest, src) => dest.Name) .ToArray(); foreach (string propertyName in commonPropertyNames) { PropertyInfo srcProperty = PropertyInfoResolver.Instance.ResolveProperty(sourceTypeInfo, propertyName); PropertyInfo destProperty = PropertyInfoResolver.Instance.ResolveProperty(destTypeInfo, propertyName); SetTesterForProperty(propertyName, new MapMemberTester <TSource, TDestination>( this, dest => destProperty.GetValue(dest, null), src => srcProperty.GetValue(src, null))); } }
private void UpdatePropertiesWithRandomValues(object instance, Random random, TypeInfo typeInfo, int depth) { PropertyInfo[] properties = PropertyEnumerator.GetPublicInstanceReadWriteProperties(typeInfo); foreach (PropertyInfo property in properties) { var value = GetRandomValue(random, property.PropertyType, property.Name, depth); if (value != null) { property.SetValue(instance, value, null); } } }