C#, .NET – Smart Duration Class

Sharp Snippets

Have you ever come across a scenario where you require to have start and end dates, validate whether these dates define valid duration, or determine overlapping duration/timespan in two given duration(s)?

If yes, here I present to you a beautiful MVVM ready, equitable, duration class which does all the above and a little more. 🙂

We will call this class TimeDuration.

TimeDuration implements two interfaces,  IEquatable and INotifyPropertyChanged. In later parts we will see the implementation of methods for IEquatable, let’s have INotifyPropertyChanged implementation first.  Include System.ComponentModel to your cs file and define a PropertyChangedEventHandler type public event PropertyChanged. Also create a private method onPropertyChanged with a return type void. The complete INotifyPropertyChanged implementation looks like this:

Basic information encapsulation this class represent consists of start time and end time. So we will have two public DateTime type properties; Start and End in this class. We wish to notify our…

View original post 298 more words

Advertisements

One thought on “C#, .NET – Smart Duration Class

  1. Pingback: C# | .NET Extension Methods | Sharp Statements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s