dimanche 30 octobre 2022

C# : is it possible to access sibling props of a prop?

Is there any way to access sibling properties of a property ? I'm interested how to access the containg type of a property.

protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
{
    var t = TypeDescriptor.GetProperties(value);
    object defaultValue = Activator.CreateInstance(value?.GetType());
    PropertyInfo propertyInfo = defaultValue.GetType().GetProperty(_property.Name);
    if (propertyInfo.GetValue(value) == _property.Value)
    {
        //TypeConverter tc = TypeDescriptor.GetConverter(someType);
    }
    else
    {

    }

    return defaultValue.Equals(value)
        ? new ValidationResult($"Parameter \"id\" cannot have its default value.")
        : null;
}




Aucun commentaire:

Enregistrer un commentaire