NullOrEmptyString

Tired of doing this: "if(s == null || s == String.Empty)"...

public class NullOrEmptyString
{
 public static NullOrEmptyString Value = new NullOrEmptyString();

public static bool operator==(NullOrEmptyString s1, string s2)

{

return ((object)s1) == null || s1.Equals(s2);

}

public static bool operator!=(NullOrEmptyString s1, string s2)

{

return !(((object)s1) == null || s1.Equals(s2));

}

public override int GetHashCode()

{

return String.Empty.GetHashCode();

}

public override bool Equals(object o)

{

return((o is string) && (o == null || (((string)o) == string.Empty)));

}

public static implicit operator string(NullOrEmptyString s)

{

return s.ToString();

}

public override string ToString()

{

return String.Empty;

}

}

2 Comments

Comments have been disabled for this content.