Monday, 17 September 2018

Few Extension methods in C#....


public static int AsInteger(this object value)
{
            if (value == null || value == DBNull.Value || value.ToString() == string.Empty)
            {
                return 0;
            }
            try
            {
                return Convert.ToInt32(value);
            }
            catch
            {
                return 0;
            }
 }
------------------------------------------------------------------------------------
public static string AsString(this object value)
{
            if (value == null || value == DBNull.Value)
            {
                return string.Empty;
            }
            return value.ToString();
}
------------------------------------------------------------------------------------
public static double AsDouble(this object value)
{
            if (value == null || value == DBNull.Value || value.ToString() == string.Empty)
            {
                return 0;
            }
            try
            {
                return Convert.ToDouble(value);
            }
            catch
            {
                return 0;
            }
}

Similar way you can add more....


Tuesday, 24 January 2017

Blog for C# help

Few Extension methods in C#....

public static int AsInteger(this object value)
{
            if (value == null || value == DBNull.Value || value.ToString() == string.Empty)
            {
                return 0;
            }
            try
            {
                return Convert.ToInt32(value);
            }
            catch
            {
                return 0;
            }
 }
------------------------------------------------------------------------------------
public static string AsString(this object value)
{
            if (value == null || value == DBNull.Value)
            {
                return string.Empty;
            }
            return value.ToString();
}
------------------------------------------------------------------------------------
public static double AsDouble(this object value)
{
            if (value == null || value == DBNull.Value || value.ToString() == string.Empty)
            {
                return 0;
            }
            try
            {
                return Convert.ToDouble(value);
            }
            catch
            {
                return 0;
            }
}

Similar way you can add more....