private Path Learn(object source, object target) { Path path = null; var sourceProps = source.GetProps(); var targetProps = target.GetProps(); var smartConventionInfo = new SmartConventionInfo { SourceType = source.GetType(), TargetType = target.GetType() }; for (var i = 0; i < sourceProps.Count; i++) { var sourceProp = sourceProps[i]; smartConventionInfo.SourceProp = sourceProp; for (var j = 0; j < targetProps.Count; j++) { var targetProp = targetProps[j]; smartConventionInfo.TargetProp = targetProp; if (!Match(smartConventionInfo)) continue; if (path == null) path = new Path { MatchingProps = new Dictionary<string, string> { { smartConventionInfo.SourceProp.Name, smartConventionInfo.TargetProp.Name } } }; else path.MatchingProps.Add(smartConventionInfo.SourceProp.Name, smartConventionInfo.TargetProp.Name); } } return path; }
/// <summary> /// Determines if 2 properties match. /// Match is determined by name and type. /// The type check is lenient towards comparing base types to nullable types. /// </summary> /// <param name="c"> /// The c. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> protected virtual bool Match(SmartConventionInfo c) { return c.SourceProp.Name == c.TargetProp.Name && (c.SourceProp.PropertyType == c.TargetProp.PropertyType || Nullable.GetUnderlyingType(c.SourceProp.PropertyType) == c.TargetProp.PropertyType || c.SourceProp.PropertyType == Nullable.GetUnderlyingType(c.TargetProp.PropertyType)); }
/// <summary> /// The name match. /// </summary> /// <param name="c"> /// The c. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> protected bool NameMatch(SmartConventionInfo c) { return c.SourceProp.Name == c.TargetProp.Name; }
protected abstract bool Match(SmartConventionInfo c);
protected virtual bool Match(SmartConventionInfo c) { return c.SourceProp.Name == c.TargetProp.Name && c.SourceProp.PropertyType == c.TargetProp.PropertyType; }
protected override bool Match(SmartConventionInfo c) { return(c.SourceProp.Name == c.TargetProp.Name); }
/// <summary> /// The learn. /// </summary> /// <param name="source"> /// The source. /// </param> /// <param name="target"> /// The target. /// </param> /// <returns> /// The <see cref="Path"/>. /// </returns> private Path Learn(object source, object target) { Path path = null; var sourceProps = source.GetProps(); var targetProps = target.GetProps(); var smartConventionInfo = new SmartConventionInfo { SourceType = source.GetType(), TargetType = target.GetType() }; for (var i = 0; i < sourceProps.Count; i++) { var sourceProp = sourceProps[i]; smartConventionInfo.SourceProp = sourceProp; var propFound = _propertyDict.ContainsKey(sourceProp.Name); // If the source prop's name is not in the allowed list, and is neither a value type nor a string, we need to check whether we should recurse or not if (!propFound && !sourceProp.PropertyType.IsValueType && sourceProp.PropertyType != typeof(string)) { // If source property is a Class ( and thus a navigational property ) and it was not found in the dictionary: Skip it if (sourceProp.PropertyType.IsClass) { continue; } if (sourceProp.PropertyType.IsGenericType && sourceProp.PropertyType.GetGenericArguments()[0].IsClass) { continue; } } for (var j = 0; j < targetProps.Count; j++) { var targetProp = targetProps[j]; smartConventionInfo.TargetProp = targetProp; if (!NameMatch(smartConventionInfo)) { continue; } if (path == null) { path = new Path { MatchingProps = new Dictionary<string, string> { { smartConventionInfo.SourceProp.Name, smartConventionInfo.TargetProp.Name } } }; } else { path.MatchingProps.Add(smartConventionInfo.SourceProp.Name, smartConventionInfo.TargetProp.Name); } } } return path; }
protected override bool Match(SmartConventionInfo c) { var name_match = (c.SourceProp.Name == c.TargetProp.Name); return name_match; }