SeanJ
SeanJ
CC#
Created by Richards on 11/17/2023 in #help
No inbuilt functions
For the second part find the middle by deviding the length by two and then do a loop of some sort to achieve what you're trying to achieve
14 replies
CC#
Created by Shinigami on 11/17/2023 in #help
✅ ValidationContext in ASP.NET
Are the dates really nullable if you're requiring dates?
31 replies
CC#
Created by Shinigami on 11/17/2023 in #help
✅ ValidationContext in ASP.NET
var model = (User)validationContext.ObjectInstance; Exactly, the above now gives you access to your whole model and it's properties. Something to consider though: 1. Do you really want to just apply the validation to one out out of the two properties? Why? Well errors/feedback, you may want to have 1 error on the FromDate and another on the TooDate that feedbacks to the user
31 replies
CC#
Created by Shinigami on 11/17/2023 in #help
✅ ValidationContext in ASP.NET
Above is pseudocode but you get the picture 🙂
31 replies
CC#
Created by Shinigami on 11/17/2023 in #help
✅ ValidationContext in ASP.NET
You can use validationContext if you want to gain a more granular access to the context of validation. For exmple your above could literally just be this:
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var dateTo = Convert.ToDateTime(value);
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var dateTo = Convert.ToDateTime(value);
}
31 replies
CC#
Created by Shinigami on 11/17/2023 in #help
✅ ValidationContext in ASP.NET
Sounds like you're beginning to understand it. Do you have the whole method? In theory Convert.ToDateTime(otherproperty.GetValue(validationContext.ObjectInstance)); is redundant as if you look at my above the Override for ValidationResult passes the value in directly.
31 replies
CC#
Created by Shinigami on 11/17/2023 in #help
✅ ValidationContext in ASP.NET
Think of it as like the context of what's being validated. Look at my recent code for example:
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var model = (PriorityServiceRegister)validationContext.ObjectInstance;
string fieldName = validationContext.MemberName;

if (model.PowerType == PowerType.Solar && fieldName == "SolarSerial")
...
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var model = (PriorityServiceRegister)validationContext.ObjectInstance;
string fieldName = validationContext.MemberName;

if (model.PowerType == PowerType.Solar && fieldName == "SolarSerial")
...
}
It provides you access to the context of that validation that's being run (Sorry if this is a bad explanation). I can now view all the properties on my model and see their values etc. Hence why you use it to get the value of whatever property you're validating
31 replies
CC#
Created by Shinigami on 11/17/2023 in #help
✅ ValidationContext in ASP.NET
Yeh essentially
31 replies
CC#
Created by Shinigami on 11/17/2023 in #help
✅ ValidationContext in ASP.NET
PropertyInfo? otherproperty = validationContext.ObjectType.GetProperty(PropertyName);
PropertyInfo? otherproperty = validationContext.ObjectType.GetProperty(PropertyName);
ObjectType would refer to the classtype so as you described 'Model Class'
31 replies
CC#
Created by ! dubby on 5/21/2023 in #help
❔ ✅ C# .NET issue, pretty simple problem but im new lol
MessageBox.Show("Successfully Registered! + (Username.Text)", "KeyAuth", MessageBoxButtons.OK, MessageBoxIcon.Information); The errors I see here is string interpolation as IceGPT said. Just so you fully understand. To use string interpolation you need to do this:
var myString = $"{var.property}";
var myString = $"{var.property}";
We include a $ sign before the string and encapsulate your variables in {} rather than round brackets not this:
var myString = $"(var.property)";
var myString = $"(var.property)";
30 replies