Ejemplo n.º 1
0
        public static Likeness <TSource, TDestination> WithInnerSpecificLikeness
        <TSource, TDestination, TSourceProperty, TDestinationProperty, TSourcePropertySubType, TDestinationPropertySubType>
        (
            this Likeness <TSource, TDestination> likeness,
            Expression <Func <TDestination, TDestinationProperty> > propertyPicker,
            Expression <Func <TSource, TSourceProperty> > sourcePropertyPicker,
            Func <Likeness <TSourcePropertySubType, TDestinationPropertySubType>, Likeness <TSourcePropertySubType, TDestinationPropertySubType> > likenessDefFunc
        )
            where TSourceProperty : class
            where TDestinationProperty : class
            where TSourcePropertySubType : class, TSourceProperty
            where TDestinationPropertySubType : class, TDestinationProperty
        {
            return(likeness.With(propertyPicker)
                   .EqualsWhen((s, d) =>
            {
                DiagnosticsWriterLocator.DiagnosticsWriter.WriteMessage(String.Format("Comparing inner properties using likeness. Source: {0} Destination: {1}.", sourcePropertyPicker, propertyPicker));

                var sourceVal = ExpressionUtils.GetValue(sourcePropertyPicker, s);
                var destVal = ExpressionUtils.GetValue(propertyPicker, d);


                return CompareUtils.CompareUsingLikeness(likenessDefFunc, sourceVal, destVal);
            }));
        }
Ejemplo n.º 2
0
        public static Likeness <TSource, TDestination> WithCollectionSequenceEquals <TSource, TDestination>
        (
            this Likeness <TSource, TDestination> likeness,
            Expression <Func <TDestination, IEnumerable> > propertyPicker,
            Expression <Func <TSource, IEnumerable> > sourcePropertyPicker
        )
        {
            return(likeness.With(propertyPicker)
                   .EqualsWhen((s, d) =>
            {
                DiagnosticsWriterLocator.DiagnosticsWriter.WriteMessage(String.Format("Comparing inner collections. Source: {0} Destination: {1}.", sourcePropertyPicker, propertyPicker));

                var sourceVal = ExpressionUtils.GetValue(sourcePropertyPicker, s);
                var destVal = ExpressionUtils.GetValue(propertyPicker, d);

                return CompareUtils.CheckIfCollectionEqual(sourceVal, destVal);
            }));
        }
        public static Likeness <TSource, TDestination> WithPropertyMap
        <TSource, TDestination, TSourceProperty, TDestinationProperty>
        (
            this Likeness <TSource, TDestination> likeness,
            Expression <Func <TDestination, TDestinationProperty> > propertyPicker,
            Expression <Func <TSource, TSourceProperty> > sourcePropertyPicker
        )
        {
            return(likeness
                   .With(propertyPicker)
                   .EqualsWhen((s, d) =>
            {
                var sourceVal = ExpressionUtils.GetValue(sourcePropertyPicker, s);
                var destVal = ExpressionUtils.GetValue(propertyPicker, d);

                return object.Equals(sourceVal, destVal);
            }));
        }