Sorry, If this question seems too broad, but I'm a little unsure how I should do this task.
I have some objects:
public class A
{
public B b {get;set;}
public C[] cList {get;set;}
}
public class B
{
public string val1 {get;set;}
}
public class C
{
public string val2 {get;set;}
}
And a set of validators:
public class AValidator : IValidator<A>
{
IEnumerable<ValidationError> Validate(A obj){...}
}
public class BValidator : IValidator<B>
{
IEnumerable<ValidationError> Validate(B obj){...}
}
public class CValidator : IValidator<C>
{
IEnumerable<ValidationError> Validate(C obj){...}
}
Error looks like this:
public class ValidationError
{
public int Code {get;set;}
public string Message {get;set;}
}
I perform validation like this:
_validator.Validate(new A()).ThrowIfInvalid();
But here is the problem, how to reference invalid property and Serialize/Deserialize this reference to use it on client?
For example, if new A().c[2].val2
is invalid, I should be able to obtain this path on server and use it on client for my view (obtain PropertyInfo, and object).
Is there some extensions/libraries in C# which provide serializable references for properties? For example, like XPath in XML.