private static GetProperties ( |
||
type | ||
behaviour | CacheBehaviour | |
Результат | IEnumerable |
private void PreparePropertyInfo(object source, object destination) { var sourceProperties = ReflectionCache.GetProperties(source); var destinationProperties = ReflectionCache.GetProperties(destination).ToDictionary(x => x.Name); propertyMap = new List <PropertyPair>(); foreach (var property in sourceProperties) { var name = property.Name; if (destinationProperties.ContainsKey(name)) { propertyMap.Add(new PropertyPair(property, destinationProperties[name], name)); destinationProperties.Remove(name); } else { propertyMap.Add(new PropertyPair(property, null, name)); } } foreach (var property in destinationProperties.Values) { propertyMap.Add(new PropertyPair(null, property, property.Name)); } }
public ComparisonResult Compare(IComparisonContext context, object value1, object value2) { var type1 = value1.GetType(); var type2 = value2.GetType(); var props1 = ReflectionCache.GetProperties(type1); var props2 = ReflectionCache.GetProperties(type2).ToDictionary(p => p.Name); var ignored = GetIgnoredPropertiesForTypes(type1, type2); var results = new List <ComparisonResult>(); foreach (var propertyInfo1 in props1) { if (ignored.Contains(propertyInfo1.Name)) { props2.Remove(propertyInfo1.Name); continue; } var propValue1 = propertyInfo1.GetValue(value1); if (!props2.ContainsKey(propertyInfo1.Name)) { if (!IgnoreUnmatchedProperties) { context.AddDifference(propValue1, "(missing)", propertyInfo1.Name); results.Add(ComparisonResult.Fail); } continue; } var propertyInfo2 = props2[propertyInfo1.Name]; var propValue2 = propertyInfo2.GetValue(value2); var innerContext = context.VisitingProperty(propertyInfo1.Name); results.Add(Inner.Compare(innerContext, propValue1, propValue2)); props2.Remove(propertyInfo1.Name); } if (!IgnoreUnmatchedProperties && props2.Count > 0) { foreach (var p in props2) { if (ignored.Contains(p.Key)) { continue; } var v = p.Value.GetValue(value2); context.AddDifference("(missing)", v, p.Key); results.Add(ComparisonResult.Fail); } } return(results.ToResult()); }