in

Is there a problem with C# new modifier with different types?


I have the following abstract class AggregateId<T> class now, but the type of the Value property there used to be a Guid. I changed it because I needed it to be a lot more generic, the problem is if I change the class in order to add a new Generic type, like AggregateId<T, TValue> it would make me perform a lot of refactoring, and I gonna end adding a lot of “noise” in the code.

The solution for this problem was change the AggregateId.Value to object type and them
using the new modifier with a different type for the classes that inherit from it.

public abstract class AggregateId<T> where T : IAggregateRoot
{
    public object Value { get; }
    protected AggregateId(object value)
    {
        Value = value;
    }
}
public class SomeClassId : AggregateId<SomeClass>
{
    public new string Value { get; }
    public MarketId(string value)
        : base(value)
    {
        Value = value;
    }
}

Now, I tried to find some information about if it is OK or why would be bad, do what I have done, but I found nothing anywhere, so my question is if there is any problem to make it the way I did?



Source: https://stackoverflow.com/questions/70607405/is-there-a-problem-with-c-sharp-new-modifier-with-different-types

Movilti — Your movie review app

A simple library to speed up CLIP inference up to 3x (K80 GPU)