C#C
C#2y ago
12 replies
Nakama

Extending a class while overwriting its properties

Hello, I'm trying to use MudCalendar and for this I need to use a CalendarItem. To make it possible to pass extra data I would like to extend my own DiscordEvent class, and followed by that whenever properties of Calendar Item are queried, retrieve data from the correct properties. I have done part of this already but it has ended with my having duplicate properties like in the picture below.
public class DiscordEvent : CalendarItem
{
    [Key]
    public int EventId { get; set; }
    public string? Name { get; set; }
    public string? Description { get; set; }
    public DateTime StartDate { get; set; }
    public TimeSpan Duration { get; set; } = TimeSpan.FromHours(1);

    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
    public DateTime ModifiedAt { get; set; } = DateTime.UtcNow;

    [NotMapped]
    public new string Id { get; set; } = Guid.NewGuid().ToString();
    [NotMapped]
    public new DateTime Start
    {
        get
        {
            return StartDate;
        }
        set
        {
            StartDate = value;
        }
    }
    [NotMapped]
    public new DateTime? End
    {
        get
        {
            return StartDate + Duration;
        }
        set
        {
            value ??= StartDate + Duration;
            Duration = value.Value - StartDate;
        }
    }
    [NotMapped]
    public new bool AllDay { get; set; }
    [NotMapped]
    public new string Text
    {
        get
        {
            return Name ?? string.Empty;
        }
        set { Name = value; }
    }
    [NotMapped]
    public new bool IsMultiDay { get; set; }
}


The duplicate properties have (Heron.MudCalendar.CalendarItem) behind them. How do I fix this?
image.png
Was this page helpful?