Compare-Net-Objects icon indicating copy to clipboard operation
Compare-Net-Objects copied to clipboard

Add DateOnly support

Open sebasijan opened this issue 3 years ago • 2 comments

Would be nice to have this built in to the library, currently using this custom converter:

using System;
using KellermanSoftware.CompareNetObjects;
using KellermanSoftware.CompareNetObjects.TypeComparers;


namespace BestConnection.Application.Auditing
{
    public class DateOnlyComparer : BaseTypeComparer
    {
        public DateOnlyComparer(RootComparer rootComparer) : base(rootComparer)
        {
        }

        public override bool IsTypeMatch(Type type1, Type type2)
        {
            return type1 == typeof(DateOnly) || type2 == typeof(DateOnly);
        }

        public override void CompareType(CompareParms parms)
        {
            var date1 = (DateOnly?)parms.Object1;
            var date2 = (DateOnly?)parms.Object2;

            if (date1 != date2)
            {
                parms.Result.Differences.Add(new Difference()
                {
                    PropertyName = parms.BreadCrumb,
                    Object1 = date1?.ToString("yyyy-MM-dd"),
                    Object2 = date2?.ToString("yyyy-MM-dd")
                });
            }
        }
    }
}

sebasijan avatar Jun 14 '22 17:06 sebasijan

@sebasijan This is a great idea. I will put that in there.

GregFinzer avatar Jun 22 '22 18:06 GregFinzer

Hello, @GregFinzer I'm looking to make some valuable pull requests for Octoberfest. I use this project at work and at home, and I would gladly help with some maintenance during the event (https://hacktoberfest.com/participation/#contributors)

floatas avatar Oct 03 '22 05:10 floatas