/// <summary> /// Convert the specified data and flag. /// </summary> /// <param name="data">Data.</param> /// <param name="flag">Flag.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public static object Convert(DataRow row, BindingFlags flag = BindingFlags.NonPublic, Type type = null) { object obj = Activator.CreateInstance(type, null); List <FieldInfo> fieldInfos = GetFields(obj.GetType(), flag); bool returnFlag = false; string tableName = Query.GetTableName(type); foreach (FieldInfo field in fieldInfos) { object data = null; if (Util.IsValueType(field.FieldType)) { string key = new SQLMaker().Underline(tableName, field.Name); if (row.ContainsKey(key)) { data = row [key]; data = ConvertIgnoreData(field, data); if (data == null || data.ToString() == "") { continue; } else { returnFlag = true; } row.Remove(key); } } else { data = Convert(row, flag, field.FieldType); } if (data != null) { field.SetValue(obj, data); } } if (returnFlag) { return(obj); } else { return(null); } }
/// <summary> /// Sets the join. /// </summary> /// <param name="fieldName">Field name.</param> /// <param name="joinTable">Join table.</param> /// <param name="joinFieldName">Join field name.</param> public void SetJoin(Type tableType, string fieldName, string joinFieldName) { string tableName = Query.GetTableName(tableType); string joinQuery = GenerateJoinSQL(tableName, this.tableName, fieldName, joinFieldName, joinType); if (joinQuery == "") { string key = Period(tableName, joinFieldName); string value = Period(this.tableName, fieldName); wheres.Add(EqualsSign(key, value)); } else { joins.Add(this.tableName); joinsQuerys.Add(joinQuery); } }
/// <summary> /// Initializes a new instance of the <see cref="Hellgate.SelectORMMaker"/> class. /// </summary> /// <param name="type">Type.</param> /// <param name="tableName">Table name.</param> public SelectORMMaker(Type type, string tableName) { this.type = type; this.tableName = tableName; if (this.tableName == "") { this.tableName = Query.GetTableName(type); } selects = new List <string> (); tables = new List <string> (); wheres = new List <string> (); joins = new List <string> (); joinsQuerys = new List <string> (); tableInfos = new List <TableInfo> (); tableInfos.Add(new TableInfo(this.type, this.tableName)); tables.Add(this.tableName); }
/// <summary> /// Sets the type. /// </summary> /// <returns>The type.</returns> /// <param name="type">Type.</param> /// <param name="index">Index.</param> public string SetType(Type type, Type parent = null) { if (type == null) { this.type = type; return(""); } this.type = type; this.tableName = Query.GetTableName(type); if (this.tableName != "") { if (!tables.Contains(this.tableName)) { tableInfos.Add(new TableInfo(this.type, this.tableName, parent)); tables.Add(this.tableName); } } return(this.tableName); }