Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

The `EquatableSourceGenerator` is a simple generator that realize the implementation of the interface IEquatable`1 in a partial class

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

Zodt/EquatableSourceGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Warning: This project is proof of concept.

License: We are using the MIT License

What's EquatableSourceGenerator?

The `EquatableSourceGenerator` is a simple generator that implements the implementation of the interface IEquatable`1 in a partial class

Explanation of how it works:

To engage a class generator, class must be marked as partial and implement the IEquatable interface
public partial class DummyModel : IEqutable<DummyModel>
{
    //Your properties
}
The `EquatableSourceGenerator` will generate a partial class of `DummyModel`. It will like that:
using System;

namespace EquatableSourceGenerator.Sample.Models
{
    partial class DummyModel
    {
        public bool Equals(DummyModel? other)
        {
            return other is not null 
                /*&& All your properties*/;
        }
        public override bool Equals(object? obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            
            return obj.GetType() == this.GetType() 
                || obj is DummyModel self && Equals(self);
        }
        public override int GetHashCode()
        {
            HashCode hashCode = new();
	    /*&& hashCode will add all your properties*/;
	    return hashCode.ToHashCode();
        }

        public static bool operator == (DummyModel? self, DummyModel? other)
        {
            return other?.Equals(self) ?? self is null;
        }
        public static bool operator != (DummyModel? self, DummyModel? other)
        {
            return !(self == other);
        }
    }
}

About

The `EquatableSourceGenerator` is a simple generator that realize the implementation of the interface IEquatable`1 in a partial class

Topics

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Languages