c# - Best practice for giving back extra information from a Validate function -


I have a class employee to ensure that all these fields have populated with valid values, save I want to be able to validate it before the class users can call valid () call before calling or they can directly call the save () and save () call again (valuyet) And if the verification fails, then possibly throw exceptions Is obtained.

Now, my (main) question is this;
If my valid () function returns a simple shell, then how do I tell the user's class which is wrong, i.e. "not across email", "id not unique" etc. For this purpose I just want to give the error string to the human user, but the principle is the same if I want the list of error codes (except that using bitmap is more logical).

  • I can use the Out parameter in my valid function, but I think it is frowned on.
  • Instead of returning to a bool, I test a string from my work and just test if it is empty (no error) - but it does not look messy and right.
  • I can simply create a single stratus for this method, which includes a string and a string with error messages, but still seems to be there.
  • I can return a bitmap of error code instead of a bool and see it, but it seems highly.
  • I can create a public property that prevents errors on the "Verification Assurances" object However, it will trust me () Call it clearly before reading it or explicitly call the property Do that which is a little wasteful.

My specific program is in C # but it seems like a fairly general "best practice" question and one I'm sure I should know the answer. Any advice received from gratitude.

I would probably go to bitmap-option just

  [ Flag] Public enum validation error {none = 0, SomeError = 1, OtherError = 2, ThirdError = 4}  

... and in the calling code, bus:

< Pre> validation error errCode = employee.Validate (); If (errCode! = Validation Error.No) {// Something}

I feel good and compact.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -