Click here to Skip to main content
15,894,343 members
Articles / Programming Languages / C#

LumiSoft MailServer

Rate me:
Please Sign up or sign in to vote.
3.79/5 (22 votes)
17 Nov 2006CPOL1 min read 323.1K   4.9K   74  
Full featured SMTP/POP3/IMAP server
using System;

namespace LumiSoft.MailServer.Filters
{
	/// <summary>
	/// Convert methods.
	/// </summary>
	public class ConvertEx
	{
		#region method ToString

		/// <summary>
		/// Converts object to string. If value == null, returns "".
		/// </summary>
		/// <param name="value">Value to  be converted.</param>
		/// <returns></returns>
		public static string ToString(object value)
		{
			if(value == null){
				return "";
			}
			else{
				return value.ToString();
			}
		}

		#endregion

		#region method ToBoolean

		/// <summary>
		/// Convert object to bool. If value == null or object can't be converted to bool, returns false.
		/// </summary>
		/// <param name="value">Value to  be converted.</param>
		/// <returns></returns>
		public static bool ToBoolean(object value)
		{
			if(value == null){
				return false;
			}
			else{
				try{
					return Convert.ToBoolean(value);
				}
				catch{
					return false;
				}
			}
		}

		#endregion

		#region method ToInt32

		/// <summary>
		/// Convert object to int. If value == null or object can't be converted to int, returns 0.
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public static int ToInt32(object value)
		{
			return ToInt32(value,0);
		}

		/// <summary>
		/// Convert object to int. If value == null or object can't be converted to int, returns 0.
		/// </summary>
		/// <param name="value">Value to convert.</param>
		/// <param name="defaultValue">Default value if value == null.</param>
		/// <returns></returns>
		public static int ToInt32(object value,int defaultValue)
		{
			if(value == null){
				return defaultValue;
			}
			else{
				try{
					return Convert.ToInt32(value);
				}
				catch{
					return defaultValue;
				}
			}
		}

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Estonia Estonia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions