public object RawGetValueOrDefaultFromMapIndex(int mapIndex) { //this check plan //get data from reader at original field //lets do proper conv technique MySqlFieldMap mapField = mapFields[mapIndex]; object value = reader.GetValue(mapField.OriginalFieldIndex); #if DEBUG Type srcType = value.GetType(); #endif switch (mapField.ConvTechnique) { case MySqlDataConversionTechnique.Direct: return(value); case MySqlDataConversionTechnique.GenString: //gen to string return(value.ToString()); case MySqlDataConversionTechnique.GenDateTime: return(DateTime.Parse(value.ToString())); case MySqlDataConversionTechnique.BlobToString: // return(value.ToString()); case MySqlDataConversionTechnique.StringToString: // if (stringConverter != null) { //use string converter to convert again return(stringConverter.Conv((string)value)); } else { return(value.ToString()); } case MySqlDataConversionTechnique.DecimalToDecimal: { return((decimal)value); } case MySqlDataConversionTechnique.DecimalToDouble: { return(Convert.ToDouble((decimal)value)); } case MySqlDataConversionTechnique.DecimalToFloat: { return((float)Convert.ToDouble(value)); } default: throw new NotSupportedException(); } }
protected void EvaluateTargetStructure(Type t) { //evaluate target objet definition //check current table defintioin first *** MySqlSubTable subTable = reader.CurrentSubTable; //get all public instance fields from current type FieldInfo[] allFields = GetPublicInstanceFields(t); //we iterate all request fields int j = allFields.Length; mapFields.Clear(); for (int i = 0; i < j; ++i) { FieldInfo field = allFields[i]; MySqlFieldDefinition fieldDef = subTable.GetFieldDefinition(field.Name); //---------------------------------- //check field type conversion //1. some basic can do direct conversion //2. use can provide custom protocol for field conversion //3. some need user decision //---------------------------------- //in this version we support only primitive type *** MySqlDataConversionTechnique foundConv; if (!MySqlTypeConversionInfo.TryGetImplicitConversion((MySqlDataType)fieldDef.FieldType, field.FieldType, out foundConv)) { //not found //TODO: //so make notification by let use make a dicision throw new NotSupportedException(); } //----------------- MySqlFieldMap fieldMap = fieldDef.IsEmpty ? new MySqlFieldMap(-1, fieldDef.Name, foundConv) : new MySqlFieldMap(fieldDef.FieldIndex, fieldDef.Name, foundConv); fieldMap.resolvedFieldInfo = field; mapFields.Add(fieldMap); } }
protected void EvaluateTableDefinition(MethodInfo met) { //check current table defintioin first *** MySqlSubTable subTable = reader.CurrentSubTable; var metPars = met.GetParameters(); //target method that we need int j = metPars.Length;//** mapFields.Clear(); for (int i = 1; i < j; ++i) { //get parameter fieldname //and type and check proper type conversion ParameterInfo metPar = metPars[i]; MySqlFieldDefinition fieldDef = subTable.GetFieldDefinition(metPar.Name); //---------------------------------- //check field type conversion //1. some basic can do direct conversion //2. use can provide custom protocol for field conversion //3. some need user decision //---------------------------------- //in this version we support only primitive type *** MySqlDataConversionTechnique foundConv; if (!MySqlTypeConversionInfo.TryGetImplicitConversion((MySqlDataType)fieldDef.FieldType, metPar.ParameterType, out foundConv)) { //not found //TODO: //so make notification by let use make a dicision throw new NotSupportedException(); } //----------------- MySqlFieldMap fieldMap = fieldDef.IsEmpty ? new MySqlFieldMap(-1, fieldDef.Name, foundConv) : new MySqlFieldMap(fieldDef.FieldIndex, fieldDef.Name, foundConv); mapFields.Add(fieldMap); } }