?
Solved

public override bool IsValid

Posted on 2014-02-14
7
Medium Priority
?
564 Views
Last Modified: 2014-02-20
I have the following class. I was wondering if someone could explain me the class. Maybe a line by line explanation will be good. I'm trying to understand public override bool IsValid(object value)

public class CheckValidYear: ValidationAttribute
{
public CheckValidYear()
{
   ErrorMessage = "The earliest opera is Daphne, 1598, by Corsi, Peri, and
Rinuccini";
}


public override bool IsValid(object value)
{
   int year = (int)value;
   if (year < 1598)
   {
      return false;
   }
   else
   {
      return true;
    }
 }
}
0
Comment
Question by:yguyon28
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 39858929
if you are just talking about the

public override

part then that just means that it is a virtual method from the base class ValidationAttribute and instead of using the default method in that class you are handling it in your derived class
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1500 total points
ID: 39858930
The public override bool IsValid(object value) part is providing an implementation for a method defined by the base ValidationAttribute class. It takes the value, converts it to an int, and then assesses its value.

If the value is less than 1598, then the method returns false to indicate that validation has failed, otherwise it returns true to indicate the value is valid.
0
 

Author Comment

by:yguyon28
ID: 39858944
Thanks for the info but how is it related to CheckValidYear()
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 22

Expert Comment

by:p_davis
ID: 39858949
it is now a method that can be used by checkvalidyear as modified
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39858952
CheckValidYear() is the constructor for the class. It is called implicitly every time an instance of the class is instantiated. All it does in your case is set the value of the classes ErrorMessage property (which is inherited from the base class).
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39859064
For completeness:

The public override bool IsValid(object value) part is providing an implementation for a method defined by either the base ValidationAttribute class or some base class further up the inheritance chain. It is quite possible that IsValid of the ValidationAttribute class is itself overriding a base (virtual) definition.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39859073
Except in this case it isn't. IsValid is defined by the base ValidationAttribute class. But the sentiment is worth bearing in mind for other scenarios.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question