So i have a domain class that should handle some notifications config and types for a proxy of all notifications kinds(email, push, sms ...).
This class have some field of a specific type that i called NotificationConfig this type have a status that indicate if the user set this notification type as On or Off on his app, and a enumeration that indicates it's type (1 = mobilePusj, 2 = email, ...).
So my class has a couple of properties of this type, like one for email, and one for mobile push.
I'm trying to build a method capable of changing the status on one of this properties looking to its enumeration type, but not using the property itself. I guess it's some sort of reflection, but i don't really know how can i make it
this is my class:
public class UserNotification : Entity, IAggregateRoot
{
private string _mobileNotificationId;
private NotificationConfig _mobileNotificationConfig;
public NotificationConfig MobileNotificationConfig => _mobileNotificationConfig;
private NotificationConfig _emailNotificationConfig;
public NotificationConfig emailNotificationConfig => _emailNotificationConfig;
public UserNotification(string mobileNotificationId, int notificationSendTypeId)
{
_mobileNotificationId = mobileNotificationId;
// start NotificationConfig via its own constructor
}
}
and i would like to make a method something like this
public void ChangeStatusByType(int notificationTypeId)
{
var rightConfig = GetTheRightPropOfConfigBasedOnTypeId();
rightConfig.SetStatusToOff();
}
This is just an idea that i would like to do since this class could need to acceppt much more notification types, just right it's only two, and as it's grow woudl make really hard to change handly every tipy of notification instance.
Aucun commentaire:
Enregistrer un commentaire