Object Validation - Page 4
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 4 of 4 FirstFirst 1234
Results 46 to 53 of 53

Thread: Object Validation

  1. #46
    Join Date
    Nov 2008
    Location
    United States
    Posts
    81

    Re: Object Validation

    Sorry, but I don't know how to create a validator for a boolean field if I always need to have a validator assigned.

    I can't even assign it to Validator class and use the default "do nothing" field because that field had to change. Since the last example you gave me returned a boolean, the "do nothing" function had to be modified.

    So now, it technically does something.

    Code:
        public class Validator<T>
        {
            public virtual bool Validate(T data) { return false; }
        }
    Three5Eight
    Using: MS C# 08 EE, MS SQL 05 EE, C++ .Net 08 EE, Vista Home Premium, XP Home

  2. #47
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Object Validation

    The default validator should return TRUE!
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #48
    Join Date
    Nov 2008
    Location
    United States
    Posts
    81

    Re: Object Validation

    Ok, I'll make the changes then. I tried to stay away from returning true because no matter what is passed into the function will always be true even if it's not valid. I figured it was safer to return false and not assume the field was valid.

    Now my IsValid() function will check all the field's Value property correctly. But I didn't know it was possible for a class to build a collection of all of the fields declared within it.

    Right now I'm checking them all manually like I shown in my code example on Post # 40
    Three5Eight
    Using: MS C# 08 EE, MS SQL 05 EE, C++ .Net 08 EE, Vista Home Premium, XP Home

  4. #49
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Object Validation

    If you remember,there was a time when the constructor for "Field" had a "this" parameter, but this broke things because we were using initializer lists....

    Building the collection is done by implementing a set of calls. during construction (which is now taking place within the business objects constuuctor.

    I dont have time tonight, but I will try to post an updated sample tomorrow morning.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  5. #50
    Join Date
    Nov 2008
    Location
    United States
    Posts
    81

    Re: Object Validation

    Interesting, I'll look forward to your example. I think that would be usefull in many places. Not just validation. I guess you learn something new everyday. In the mean time I'll keep working on cleaning up my classes after all this.
    Three5Eight
    Using: MS C# 08 EE, MS SQL 05 EE, C++ .Net 08 EE, Vista Home Premium, XP Home

  6. #51
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Object Validation

    Ironically this process is leading directly toward some material I am preparing for publication (that does handle alot more than validation). If the current implementation works for your immediate needs, it may be best to wait a week or so, so you can see the "real" design.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #52
    Join Date
    Nov 2008
    Location
    United States
    Posts
    81

    Re: Object Validation

    Well everything works except the IsValid() function right now. I have many more classes to design, and if I can get the IsValid() down first then I do not have to rewrite all those classes.

    But, other then that everything seems to be working. However, I haven't tested it at run time yet to see if the code really does what its supposed to. I wanted to get this last piece worked out first so everything is working when I test it.
    Three5Eight
    Using: MS C# 08 EE, MS SQL 05 EE, C++ .Net 08 EE, Vista Home Premium, XP Home

  8. #53
    Join Date
    Nov 2008
    Location
    United States
    Posts
    81

    Re: Object Validation

    TheCPUWizard:

    In reguard to your PM here is the new project you requested. I think this is what you needed.
    Attached Files Attached Files
    Three5Eight
    Using: MS C# 08 EE, MS SQL 05 EE, C++ .Net 08 EE, Vista Home Premium, XP Home

Page 4 of 4 FirstFirst 1234

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center