C
Casper
Hi
I would like to perform some conditional validation on fields in a class and
am not sure of the best way to do this.
These fields can be mandatory or optional depending on whether other fields
are set.
Here is the method which has an input parameter of type CQuery (a class):
response = ProcessQuery(CQuery)
I would like to validate this parameter and check that all required fields
are set correctly.
Here are the fields :
Tenancy - this can be either Freehold or Leasehold
LengthOfLease - req' if Tenancy is Leasehold..
Landlord - req'd if Tenancy is Leasehold
PropertyValue - req'd if Tenancy is freehold.
The value for Tenancy, dictates which other field are mandatory or optional.
Is there a good way to do this without resorting to nested If else, If else,
if else etc.. ?
I have other classes which are more complex and these would require some
complex validation rules...and have many fields..
I have thought about serialising the class to XML at runtime and then
perhaps validating the XML against a schema, but am not sure if this is the
best way.
I have also considered using reflection, but then would still require some
way to apply the validation rules.
thanks in advance!
I would like to perform some conditional validation on fields in a class and
am not sure of the best way to do this.
These fields can be mandatory or optional depending on whether other fields
are set.
Here is the method which has an input parameter of type CQuery (a class):
response = ProcessQuery(CQuery)
I would like to validate this parameter and check that all required fields
are set correctly.
Here are the fields :
Tenancy - this can be either Freehold or Leasehold
LengthOfLease - req' if Tenancy is Leasehold..
Landlord - req'd if Tenancy is Leasehold
PropertyValue - req'd if Tenancy is freehold.
The value for Tenancy, dictates which other field are mandatory or optional.
Is there a good way to do this without resorting to nested If else, If else,
if else etc.. ?
I have other classes which are more complex and these would require some
complex validation rules...and have many fields..
I have thought about serialising the class to XML at runtime and then
perhaps validating the XML against a schema, but am not sure if this is the
best way.
I have also considered using reflection, but then would still require some
way to apply the validation rules.
thanks in advance!