Esempio n. 1
0
        /// <summary>
        /// Simples the difference.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        /// <returns></returns>
        public static ValueDiffResult <T> SimpleDiff <T>(this T source, T destination)
        {
            var result = new ValueDiffResult <T>
            {
                SourceValue      = source,
                DestinationValue = destination,
                DiffResult       = DiffResult.NoChange
            };

            if (source == null)
            {
                if (destination != null)
                {
                    result.DiffResult = DiffResult.DestinationAdded;
                }
            }
            else if (destination == null)
            {
                result.DiffResult = DiffResult.SourceDeleted;
            }
            else
            {
                result.DiffResult = source.Equals(destination) ? DiffResult.NoChange : DiffResult.Replace;
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Simples the difference.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="ignoreCase">if set to <c>true</c> [ignore case].</param>
        /// <returns></returns>
        public static ValueDiffResult SimpleStringDiff(this string source, string destination, bool ignoreCase = false)
        {
            var result = new ValueDiffResult
            {
                SourceValue      = source,
                DestinationValue = destination,
                DiffResult       = DiffResult.NoChange
            };

            if (string.IsNullOrEmpty(source))
            {
                if (!string.IsNullOrEmpty(destination))
                {
                    result.DiffResult = DiffResult.DestinationAdded;
                }
            }
            else if (string.IsNullOrEmpty(destination))
            {
                if (!string.IsNullOrEmpty(source))
                {
                    result.DiffResult = DiffResult.SourceDeleted;
                }
            }
            else
            {
                result.DiffResult = source.Equals(destination,
                                                  ignoreCase ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture)
                    ? DiffResult.NoChange
                    : DiffResult.Replace;
            }

            return(result);
        }