Exemplo n.º 1
0
    public static T Read <T>(this DataReader reader, string column, T defaultValue = default(T))
    {
        var value = reader[column];

        return((DbNull.Equals(value))
                ? defaultValue
                : Convert.ChangeType(value, typeof(T)));
    }
		public static TDestination As<TDestination> (this object source, TDestination defaultValue = default(TDestination))
		{
			if (source is TDestination)
				return (TDestination) source;
			if (source == null || DbNull.Equals(source))
				return defaultValue;
				
			Func<object, TDestination> func;
			// Check if we have a func for the desired type...
			if(_MyConverter.TryGetValue(typeof(TDestination), out func);
			{
                                // ... and call it.
				return func(source);
			}
			// Nothing suitable to find.
			throw new ArgumentException("The type " + typeof(TDestination).Name + " is not supported.");
		}