Fody / Equals

Generate Equals, GetHashCode and operators methods from properties.
MIT License
110 stars 26 forks source link

Nullable enum cause circular reference #480

Open michalciolek opened 1 year ago

michalciolek commented 1 year ago

Describe the issue

I added nullable to my enum field in class (with [Equls]):

#nullable enable

namespace NullableEnum
{
    [Equals]
    public class Example
    {
        /// <summary>
        /// This adds a circular reference to self (NullableEnum.exe)!
        /// </summary>
        public ExampleEnum? ExampleEnum { get; set; }

        public static bool operator ==(Example? left, Example? right) => Operator.Weave(left, right);
        public static bool operator !=(Example? left, Example? right) => Operator.Weave(left, right);
    }
}

This cause my result binary to have a (circular) reference to itself:

references

Without nullability, in enum, my result binary does not have reference to itself.

Minimal Repro

I have created a minimal project with this issue: https://github.com/michalciolek/NullableEnum-fody-equals

tom-englert commented 1 year ago

I would recommend to switch to a source generator to auto-implement the equality pattern.

michalciolek commented 1 year ago

@tom-englert can you elaborate because I don't understand. Now I manually wrote the equals code (using visual studio code generator) as a solution. That's what you mean?

tom-englert commented 1 year ago

Something like this https://github.com/diegofrata/Generator.Equals