public CassandraTypeSerializerAttribute(Type serializer) { // Contract, targetted implementation type must implement our interface if (!typeof(ICassandraTypeSerializer).IsAssignableFrom(serializer)) { throw new ArgumentException(string.Format("{0} does not implement ICassandraTypeSerializer interface", serializer)); } // Store the type for consumer-code introspection TypeSerializer = serializer; // Get the public constructors var ctors = serializer.GetConstructors(); // Determine if there is a constructor which passed the serialized object's type var typeCtor = ctors.Where(ctor => { var prms = ctor.GetParameters(); return(prms.Length == 1 && prms.First().ParameterType == typeof(Type)); }).FirstOrDefault(); // Determine if there is a constructor which passed the serialized object's type as well as access to the default serializer and deserializer (recursable) var recurseCtor = ctors.Where(ctor => { var prms = ctor.GetParameters().ToArray(); return(prms.Length == 3 && prms[0].ParameterType == typeof(Type) && prms[1].ParameterType == typeof(Func <Type, Func <object, byte[]> >) && prms[2].ParameterType == typeof(Func <Type, Func <byte[], object> >)); }).FirstOrDefault(); // Populate the Serializer field with the appropriate delegate if (recurseCtor != null) { Serializer = (type, defaultSerializer, defaultDeserializer) => EnlightenmentMgr.CreateSerializer(serializer, type, defaultSerializer, defaultDeserializer); } else if (typeCtor != null) { Serializer = (type, defaultSerializer, defaultDeserializer) => EnlightenmentMgr.CreateSerializer(serializer, type); } else { Serializer = (type, defaultSerializer, defaultDeserializer) => EnlightenmentMgr.CreateSerializer(serializer); } }
// ReSharper restore StaticFieldInGenericType public static TI Create <TI>(string customType, params object[] prms) { if (string.IsNullOrEmpty(customType)) { string emptyTypeMsg = string.Format("Expecting nickname or qualified class name for '{0}'", typeof(TI).AssemblyQualifiedName); throw new ArgumentException(emptyTypeMsg); } Type type; if (!_descriptor.Definition.TryGetValue(customType, out type)) { type = Type.GetType(customType); } if (null == type || !typeof(TI).IsAssignableFrom(type)) { string invalidTypeMsg = string.Format("'{0}' is not a valid type", customType); throw new ArgumentException(invalidTypeMsg); } return(EnlightenmentMgr.Create <TI>(type, prms)); }
public static ICqlCommandBuilderBuild ToPropertyBag(this ICqlCommandBuilderTo @this) { var factory = EnlightenmentMgr.PropertyBagDataMapperFactory(); return(@this.Set(factory)); }
public static void Shutdown() { EnlightenmentMgr.ClusterManager().Shutdown(); }
public static void Configure(CassandraSharpConfig config) { EnlightenmentMgr.ClusterManager().Configure(config); }
public static ICluster GetCluster(string name) { return(EnlightenmentMgr.ClusterManager().GetCluster(name)); }
public static ICluster GetCluster(ClusterConfig clusterConfig) { return(EnlightenmentMgr.ClusterManager().GetCluster(clusterConfig)); }
public static ICqlCommandBuilderTo FromPoco(this ICqlCommandBuilderFrom @this) { var factory = EnlightenmentMgr.PocoDataMapperFactory(); return(@this.Set(factory)); }
public static ICqlCommandBuilderBuild ToOrdinal(this ICqlCommandBuilderTo @this) { var factory = EnlightenmentMgr.OrdinalDataMapperFactory(); return(@this.Set(factory)); }
public ICqlCommand Build() { return(EnlightenmentMgr.CommandFactory().Create(_cluster, _factoryFrom, _factoryTo)); }
public static Task AsFuture(this IObservable <NonQuery> observable, CancellationToken?token = null) { return(EnlightenmentMgr.Future().AsFuture(observable, token)); }
public static Task <IList <T> > AsFuture <T>(this IObservable <T> observable, CancellationToken?token = null) { return(EnlightenmentMgr.Future().AsFuture(observable, token)); }