Esempio n. 1
0
        /// <summary>
        /// Casts the supplied value to type t
        /// </summary>
        /// <param name="t">the target type</param>
        /// <param name="value">the value to be casted</param>
        /// <returns>The casted value</returns>
        public static object CastToType(Type t, object value)
        {
            if (value is decimal)
            {
                return(Convert.ChangeType(value, t));
            }

            return(CLTypeConverter.Convert(t, value));
        }
Esempio n. 2
0
        public void TypeConversion()
        {
            float  f  = float.MaxValue / 2;
            byte   b  = (byte)CLTypeConverter.Convert(typeof(byte), f);
            float4 f4 = new float4(f);
            uchar4 i4 = (uchar4)CLTypeConverter.Convert(typeof(uchar4), f4);

            Assert.True(b == 128);

            for (int i = 0; i < 4; i++)
            {
                byte s = i4[i];
                Assert.True(s == 128);
            }
        }