Ejemplo n.º 1
0
        public static ListType <T> From <TIn>(List <TIn> obj)
        {
            //Check to make sure we can convert
            if (ComponentType.CreateInstance().CanConvertFrom(typeof(TIn)))
            {
                return(new ListType <T>(obj.Select(o => (T)CassandraObject.GetCassandraObjectFromObject(o, typeof(T)))));
            }

            throw new ArgumentException(string.Format("can't convert list of type {0} to ListType of type {1}", typeof(TIn), typeof(T)));
        }
Ejemplo n.º 2
0
        public static MapType <TKey, TValue> From <TKeyIn, TValueIn>(IDictionary <TKeyIn, TValueIn> obj)
        {
            //Check to make sure we can convert
            if (KeyType.CreateInstance().CanConvertFrom(typeof(TKeyIn)) && ValueType.CreateInstance().CanConvertFrom(typeof(TValueIn)))
            {
                return(new MapType <TKey, TValue>(obj.ToDictionary(
                                                      k => (TKey)CassandraObject.GetCassandraObjectFromObject(k.Key, KeyType),
                                                      v => (TValue)CassandraObject.GetCassandraObjectFromObject(v.Value, ValueType))));
            }

            throw new ArgumentException(string.Format("can't convert IDictionary of type {0},{1} to MapType of type {2},{3}", typeof(TKeyIn), typeof(TValueIn), typeof(TKey), typeof(TValue)));
        }