C
C#9mo ago
gaben

Add attribute to property in base class from derived class when base property already has attribute

I want the derived class's property to have both the added attribute and any that were in the base class:
public abstract class BaseClass
{
[SomeAttribute]
public virtual string SomeProperty { get; set; } = "";
}

public class DerivedClass : BaseClass
{
[SomeOtherAttribute]
public string SomeProperty { get; set; } = "";
}
public abstract class BaseClass
{
[SomeAttribute]
public virtual string SomeProperty { get; set; } = "";
}

public class DerivedClass : BaseClass
{
[SomeOtherAttribute]
public string SomeProperty { get; set; } = "";
}
DerivedClass -> SomeProperty should have both the SomeAttribute and SomeOtherAttribute attributes
2 Replies
Sunny99
Sunny999mo ago
In the derived class all you need is to override the (someProperty) method and add changes you want
gaben
gaben9mo ago
doing so won't carry over SomeAttribute, unfortunately
No description