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

  • SEARCH
  • Home
  • 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 6178635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:29:26+00:00 2026-05-24T00:29:26+00:00

I am new to C# so its quite possible that this has a fairly

  • 0

I am new to C# so its quite possible that this has a fairly simple solution but I haven’t found anything I’d consider elegant. If you need any additional information or are confused about what I’m asking in any way, let me know and I will get back to you as soon as I can.

Currently the way create validation rules (for when someone submits a form), like so:

new ValidationRuleInstance<DetailsPresenter>(
    new IsValidDateRule<DetailsPresenter>(m => m.StartDate, "StartDate"),
    new ValidationRuleInterpretation(Severity.Failure, "StartDateMustBeValid", "Must enter valid start date (dd/mm/yyyy)")
),

What I’m attempting to do is create a Validation rule to check if the date that I was give occurred in the past. What I tired is this:

new ValidationRuleInstance<DetailsPresenter>(
    new FailIfTrueRule<DetailsPresenter>(m => (DateTime.Parse(m.StartDate).AddDays(1) < DateTime.Now) ,"StartDate"),
    new ValidationRuleInterpretation(Severity.Failure, "StartDateCannotBeInThePast", "Your start date cannot be in the past")
),

This is works… Most of the time (P.S. I’m adding one day so that entering the current date doesn’t produce an error).

The problem is that if someone submits a String that cannot be parsed into a date time object (eg. 725/2011 instead of 7/25/2011) the whole thing blows up.

I have tried using TryParse, however that returns a Boolean not a Time-Date object.

Am I going to have to write my own method to parse a String and always return a DateTime object? Can I catch the exception and ignore it? (there is a separate rule already in place for checking if the string is valid)

  • 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-24T00:29:26+00:00Added an answer on May 24, 2026 at 12:29 am

    There’s no reason you can’t use a multi-line block of code in a lambda. You just have to enclose the code in brackets and issue explicit return statements, rather than just specifying a single expression that implicitly returns its value.

    new ValidationRuleInstance<DetailsPresenter>(
        new FailIfTrueRule<DetailsPresenter>(m => 
    {
        DateTime value;
    
        if(DateTime.TryParse(m.StartDate, out value))
        {
            return value.AddDays(1) < DateTime.Now;
        }
        else // parsing failed, return whatever value is appropriate
        {
    
        }
    } ,"StartDate"),
        new ValidationRuleInterpretation(Severity.Failure, "StartDateCannotBeInThePast", "Your start date cannot be in the past")
    ),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to node.js and I've found its quite complicated separating a project
I've read that Firefox 3.5 has a new feature in its parser ? Improvements
(I'm fairly certain the answer to this question is quite simply no but I
I'm quite new to Flex and wondered if other developers actually use its stylesheet
First, I apologize if this has been answered. I've seen many similar questions but
So I have this website that has a search feature which searches a table
The new system I'm starting has several domains that are just join tables for
I have to admit in advance that I'm quite new to MVC, I've been
I'm currently experiencing with the new c++0x variadic templates, and it's quite fun, Although
Im new to Web Development and its principles so apologies if my question does

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.