public void ExecutesFallbackActionAssignedInConstructorWhenExecutedTypeNotFoundOrNull()
        {
            var swithWithFallback = new TypeSwitch<int>( () => 0 );
            swithWithFallback.Set( typeof(int), () => 1 );

            var result = swithWithFallback.Execute( typeof(bool) );

            Assert.AreEqual( 0, result );
        }
Beispiel #2
0
        public void ExecutesFallbackActionAssignedInConstructorWhenExecutedTypeNotFoundOrNull()
        {
            var swithWithFallback = new TypeSwitch( StringAction );
            swithWithFallback.Set( typeof(int), IntegerAction );

            swithWithFallback.Execute( typeof(bool) );

            Assert.IsTrue( _stringActionInvoked );
        }
Beispiel #3
0
        public static SqlDbType GetSqlDbType(Type type, string propName)
        {
            var       prop    = type.GetProperty(propName);
            SqlDbType sqlType = SqlDbType.BigInt;

            var ts = new TypeSwitch()
                     .Case <string>(() => sqlType   = SqlDbType.VarChar)
                     .Case <int>(() => sqlType      = SqlDbType.Int)
                     .Case <DateTime>(() => sqlType = SqlDbType.DateTime2)
                     .Case <bool>(() => sqlType     = SqlDbType.Bit)
                     .Case <decimal>(() => sqlType  = SqlDbType.Decimal);

            ts.Switch(prop.PropertyType);
            return(sqlType);
        }
 public void Setup()
 {
     _switch = new TypeSwitch<int>();
 }