/// <summary> /// Default Ctor. /// <para>If DB has null string value, INSTANCE property (can be private or internal BUT not PUBLIC and not STATIC) /// will contain string.empty value.</para> /// </summary> /// <param name="dbcolumnName">Name of DBColumn in the select query.</param> /// <param name="stringConversionType">This value has NO impact on NON-String type values.</param> /// <param name="additionalDataDbColumnName">Name of the db column in AdditionalDataQuery /// (When Cache config has AdType = AdditionalData.Database).</param> public AsyncCacheAttribute(string dbcolumnName, CacheStringConversion stringConversionType, string additionalDataDbColumnName = null) { ConversionType = stringConversionType; DbColumnName = dbcolumnName; AdditionalDataDbColumnName = additionalDataDbColumnName; }
public Action <TMap, DbDataReader, int> StringSetter(Type dbcolType, CacheStringConversion conversionType, Delegate setter, string columnName) { Func <Delegate, string, Action <TMap, DbDataReader, int> > outFunc; return(_stringerBinders.TryGetValue(dbcolType, out outFunc) ? outFunc(setter, columnName) : StringSetter(conversionType, setter, columnName)); }
private Action <TMap, DbDataReader, int> PrepareSetter(Type columnType, Type propertyType, CacheStringConversion conversionType, Delegate setter, string columnName, string propName) { if (columnType == null) { return(propertyType == typeof(string) ? _propertySetterBuilder.StringSetter(conversionType, setter, columnName) : _propertySetterBuilder.Setter(propertyType, setter, columnName)); } return(propertyType == typeof(string) ? _propertySetterBuilder.StringSetter(columnType, conversionType, setter, columnName) : _propertySetterBuilder.Setter(columnType, propertyType, setter, columnName, propName)); }
public Action <TMap, DbDataReader, int> StringSetter(CacheStringConversion conversionType, Delegate setter, string columnName) { return(StaticCalls.GetStringBinder <TMap>(setter, conversionType, columnName)); }
public static Action <TMap, DbDataReader, int> GetStringBinder <TMap>(Delegate propDelegate, CacheStringConversion conversionType, string columnName) { var castedPropertySetter = propDelegate as PropertySetter <TMap, string>; if (castedPropertySetter == null) { throw new InvalidCastException( $"Unable to cast the String Property setter (DbColumn:{columnName}) as " + $"{typeof(PropertySetter<TMap, string>).Name}. Given delegate type is: {propDelegate.GetType()}"); } switch (conversionType) { case CacheStringConversion.None: Expression <Action <TMap, DbDataReader, int> > expr1 = (obj, odr, index) => castedPropertySetter(obj, odr.IsDBNull(index) ? string.Empty : odr[index].ToString()); return(expr1.Compile()); case CacheStringConversion.OnlyTrim: Expression <Action <TMap, DbDataReader, int> > expr2 = (obj, odr, index) => castedPropertySetter(obj, odr.IsDBNull(index) ? string.Empty : odr[index].ToString().Trim()); return(expr2.Compile()); case CacheStringConversion.ToLower: Expression <Action <TMap, DbDataReader, int> > expr3 = (obj, odr, index) => castedPropertySetter(obj, odr.IsDBNull(index) ? string.Empty : odr[index].ToString().ToLower()); return(expr3.Compile()); case CacheStringConversion.ToLowerWithTrim: Expression <Action <TMap, DbDataReader, int> > expr4 = (obj, odr, index) => castedPropertySetter(obj, odr.IsDBNull(index) ? string.Empty : odr[index].ToString().SafeTrimLower()); return(expr4.Compile()); case CacheStringConversion.ToUpper: Expression <Action <TMap, DbDataReader, int> > expr5 = (obj, odr, index) => castedPropertySetter(obj, odr.IsDBNull(index) ? string.Empty : odr[index].ToString().ToUpper()); return(expr5.Compile()); case CacheStringConversion.ToUpperWithTrim: Expression <Action <TMap, DbDataReader, int> > expr6 = (obj, odr, index) => castedPropertySetter(obj, odr.IsDBNull(index) ? string.Empty : odr[index].ToString().ToUpper().Trim()); return(expr6.Compile()); case CacheStringConversion.RemovedInterwordSpace: Expression <Action <TMap, DbDataReader, int> > expr7 = (obj, odr, index) => castedPropertySetter(obj, odr.IsDBNull(index) ? string.Empty : odr[index].ToString().Replace(" ", "")); return(expr7.Compile()); case CacheStringConversion.RemovedInterwordSpaceAndToLower: Expression <Action <TMap, DbDataReader, int> > expr8 = (obj, odr, index) => castedPropertySetter(obj, odr.IsDBNull(index) ? string.Empty : odr[index].ToString().Replace(" ", "").ToLower()); return(expr8.Compile()); case CacheStringConversion.RemovedInterwordSpaceAndToUpper: Expression <Action <TMap, DbDataReader, int> > expr9 = (obj, odr, index) => castedPropertySetter(obj, odr.IsDBNull(index) ? string.Empty : odr[index].ToString().Replace(" ", "").ToUpper()); return(expr9.Compile()); default: throw new NotImplementedException($"{conversionType} not implemented."); } }