public CassandraObject CreateInstance()
        {
            if (_type == null)
            {
                Init();
            }

            CassandraObject obj;

            if (_type == typeof(CompositeType))
            {
                obj = new CompositeType(_compositeTypes);
            }
            else if (_type == typeof(DynamicCompositeType))
            {
                obj = new DynamicCompositeType(_dynamicCompositeType);
            }
            else
            {
                obj = Activator.CreateInstance(_type) as CassandraObject;
            }

            if (obj == null)
            {
                return(null);
            }

            return(obj);
        }
        private static DynamicCompositeType ConvertFrom(object o)
        {
            var type = new DynamicCompositeType();

            type.SetValue(o);
            return(type);
        }
        private static T ConvertTo <T>(DynamicCompositeType type)
        {
            if (type == null)
            {
                return(default(T));
            }

            return(type.GetValue <T>());
        }
Exemplo n.º 4
0
        public void CassandraType_Cast()
        {
            // arrange
            var expected = new CassandraObject[] { (AsciiType)"string1", (LongType)300L };

            // act
            DynamicCompositeType actualType = expected;
            CassandraObject      actual     = actualType;

            // assert
            Assert.True(expected.SequenceEqual((CassandraObject[])actual));
        }
Exemplo n.º 5
0
        public void Implicit_ByteArray_Cast()
        {
            // arrange
            var expected = new CassandraObject[] { (AsciiType)"string1", (LongType)300 };

            byte[] bytes = GetBytes(expected);

            // act
            DynamicCompositeType actual = bytes;

            // assert
            Assert.True(expected.SequenceEqual(actual));
        }