I'm trying to setup data annotation validation for an object in my model and it has a special need. I have to essentially take some extra properties that I'm adding and combine them to get the value of a real property. For example I have a base object:
Task {
public DateTime? Due
}
But my form has the fields of:
Task.DueDate
Task.DueTimeHour
Task.DueTimeMinute
Task.DueTimePostfix
So I tried:
Task {
public string DueDate
public string DueTimeHour
public string DueTimeMinute
public string DueTimePostfix
}
Which works, but I then want the model to automatically populate the value of Due
with the parsed value of all the other ones. I don't know how to do that.
I would have to override the getter/setters of Due
in the metadata buddy class, but that class wouldn't be aware of the extra properties I've given to the original class. Plus I have a feeling that if I mess with those I will have problems retrieving real values from the database.
So I'm hoping that someone here may have an idea on how I can accomplish what I want. If I'm going about it completely wrong I would appreciate being guided back on the right path.
Thanks in advance for any suggestions!
UPDATE
So, I might have found a solution for the first part by having both the original class and the metadata buddy class extend from another base class which contains all the properties. Thus both classes see the properties and can use them.
Now, I'm having a hard time setting the value for the Due
property based off of the other properties. Help would be appreciated on this front.