Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy Way to Validate if object parameters are not empty

Status
Not open for further replies.

nicklieb

Programmer
Oct 17, 2002
383
GB
Hi,

I have a very large object that has around 50 parameters, and was looking for an easy method to validate that the paremeters are populated.

I don't really want to go throuhg each parameter with

Code:
if (object.Parameter == String.Empty) {
    //then do something
}

I have seen something about using Reflection, but a comment says that it has a great impact on performance.

any ideas?

thanks in advance
 
Hi,

One suggestion: Have default values for your class viariables
 
You can:
Assign default values to your object, and then compare your real object against a newly instantiated instance using the Hashcode.

Or you can use reflection with the GetProperties method and loop thru them, checking each.

BTW: Doing a (myString.Length > 0) test is faster than comparing against String.Empty.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top