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); } }
//------------------------------------------------------- //user's bound data values public void AddWithValue(string key, object value) { //get type of value if (value == null) { SetNull(key); return; } //get type of value switch (MySqlTypeConversionInfo.GetProperDataType(value)) { //switch proper type default: case ProperDataType.Unknown: throw new Exception("unknown data type?"); case ProperDataType.String: AddWithValue(key, (string)value); break; case ProperDataType.Buffer: AddWithValue(key, (byte[])value); break; case ProperDataType.Bool: AddWithValue(key, (bool)value); break; case ProperDataType.Sbyte: AddWithValue(key, (sbyte)value); break; case ProperDataType.Char: AddWithValue(key, (char)value); break; case ProperDataType.Int16: AddWithValue(key, (short)value); break; case ProperDataType.UInt16: AddWithValue(key, (ushort)value); break; case ProperDataType.Int32: AddWithValue(key, (int)value); break; case ProperDataType.UInt32: AddWithValue(key, (uint)value); break; case ProperDataType.Int64: AddWithValue(key, (long)value); break; case ProperDataType.UInt64: AddWithValue(key, (ulong)value); break; case ProperDataType.DateTime: AddWithValue(key, (DateTime)value); break; case ProperDataType.Float32: AddWithValue(key, (float)value); break; case ProperDataType.Double64: AddWithValue(key, (double)value); break; case ProperDataType.Decimal: AddWithValue(key, (decimal)value); break; } }