Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3677448
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:13:22+00:00 2026-05-19T03:13:22+00:00

We are using a validation framework (something we have cooked up ourselves) which allows

  • 0

We are using a validation framework (something we have cooked up ourselves) which allows us to do validation assertions on objects.

string Validation<T,U>(T obj, Func<T,U> selector, Validations.IsNotNull,
                       string failureMessage) 
       {
           var propertyToBeValidated = selector(obj);
           // Do validation here, if it fails, return failure message
       }

The problem with this is:

  • The message is mandatory. We cannot auto generate a meaningful message looking at the selector.

The other option is to change the signature of the above method to:

string Validation<T,U>(T obj, Expression<Func<T,U>> selector, 
                       Validations.IsNotNull, string failureMessage = null) 

In this case the failure message is optional and we can get the property name from the expression tree.

However, this requires an Expression.Compile before the selector can be invoked and slows down things by 3 orders of magnitude. As of now the messages are mandatory but as the validations are somewhere else, refactoring requires changing the validation messages too.

What would you suggest:

  • Change signature and accept expressions. Cache the compiledd expressions if need be and auto generate the messages. Is a message is provided, use that instead.
  • Changing messages by hand is an acceptable overhead as you have a good test coverage. Leave the signature as is and avoid the additional complexity and the performance hit.

Edit: We are using this validation framework accross multiple layers. In out controllers for validating input parameters, in our services for validating incoming requests and in our integration tests for validating state of objects after some operations. The cost of expression.Compile is insignificant compared to some of these costs, but not insignificant compared to datbase access, etc.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:13:23+00:00Added an answer on May 19, 2026 at 3:13 am

    We concluded that for us it made the most sense to use an Expression.
    The overhead of the DB and WS calls was far greater than this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started using aspects for parameter validation in our development framework. It works
I have an app using Spring, JPA (Hibernate) and the Java validation framework (Hibernate
I am using Zend Framework I have a form that allows me to create
I have a situation where I am using wpf data binding and validation using
The struts2 validation framework allows you to define your validation for an action or
I have been using the Zend Framework with an MVC configuration, read about Ruby
I'm implementing data validation in WPF using the Prism MVVM framework. I'm using clean
I am making a PHP image uploader using the Zend Framework which will upload
I'm trying to get server-side validation of an Entity Framework String Property to work.
I'm using hibernate validator framework with Spring. A class implementing the Spring Validator validates

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.