Implementation Of Happiness in C Sharp
Dated: 24 Dec, 2010 01:28:37 AM
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

.
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