Is there any way I can get the complete path of the property from the property itself ?
I have code design below as something:
class A
{
B BProperty { get; set; }
D DProperty { get; set; }
}
class B
{
D DProperty { get; set; }
}
class D
{
int Value { get; set; }
}
class Verification
{
public static void VerifyAProperty(A source, A dest)
{
VerifyBProperty(source.BProperty, dest.BProperty);
VerifyDProperty(source.DProperty, dest.DProperty);
}
public static void VerifyBProperty(B source, B dest)
{
VerifyDProperty(source.DProperty, dest.DProperty);
}
public static void VerifyDProperty(D source, D dest)
{
//// Here I want to verify source.value with dest.value and if they do not match I want to show an error message.
//// I have requirement to show the complete path of property that is under verification.
//// i.e either A->D->value or A->B->D->value
}
}
This is just a small part of my problem. I have number of similar verification to be done on number of different properties that can be at multiple places in the hierarchy.
I need to verify the source property with the destination property and in case if both do not match, show an error message that provides the path of the property that did not match.
I have tried something by passing a string property to VerifyProperty()
function that will be appended as we go down the hierarchy. I just want to know if there is any better way to achieve this.