Implementation Of Happiness in C Sharp

Dated: 24 Dec, 2010 01:28:37 AM
Implementation of happiness in c sharp
Click on image to enlarge
Today I got a code function signature from a friend "Convert.ToAllsWell(What ever happens)" and thought of implementing happiness in C sharp.

The code below is my implementation of that function. This code do compiles, so you can safely add it to your projects to make coding experience happier ;) :D .




class Convert
{
    public Happiness ToAllsWell(object whateverHappens)
    {
        if (whateverHappens.GetType() == typeof(SomethingNotGood))
            IgnoreIt((SomethingNotGood)whateverHappens);

        Happiness iAmHappy = new Happiness();
        GC.KeepAlive(iAmHappy);
        return iAmHappy;
    }

    private void IgnoreIt(SomethingNotGood notGoodItem)
    {
        try
        {
            notGoodItem.Dispose();
        }
        catch
        {
            // ignore exception, to ensure that you ignore it totally ;)
        }
    }
}

/// <summary>
/// Represents happiness in life.
/// </summary>
class Happiness
{
    public bool YesIAmHappy
    {
        get
        {
            return YesIAmHappy;
        }
        set
        {
            if (value == false)
                throw new System.InvalidOperationException("Happiness cannot contain false value. :)");

            YesIAmHappy = value;
        }
    }

    public Happiness()
    {
        YesIAmHappy = true;
    }
}

/// <summary>
///
This class represents all the entities in life that you do not like.
/// They may not be bad, but you don't like them.
/// This is the base class of everything that is not good in life.
/// </summary>
class SomethingNotGood: IDisposable
{
    public object Description { get; set; }

    public SomethingNotGood(object description)
    {
        this.Description = description;
    }

    public void Dispose()
    {
        // release all the bad memories
        // remove all the bad effects

    }
}



Leave your comments to let me know what improvements can be made to this code.

Like this article? Now share it with your friends

 

1 Comment.....

Dig
12/24/2010 2:41:31 AM

Great way to incorporate happiness in Programmer's life :-). Please provide me a copy.



Post Comment

Name:  
Email:  
You will receive an email to approve your comment.

Comment:  


Free subscriptions
Provide your email address to recieve my articles by email. I will never share your address, and there is a link to unsubscribe in every mail.



Follow me on twitter @mndworld

Popular Articles

Recent Articles