//--------------------------------------------------------------------- public Prop <T> defProp <T>(Dictionary <string, string> map_param, string key, T default_value) { PropDef prop_def = new PropDef(key, typeof(T)); mMapPropDef[prop_def.getKey()] = prop_def; Prop <T> prop = new Prop <T>(prop_def, default_value); mMapProp[prop_def.getKey()] = prop; if (map_param != null && map_param.ContainsKey(prop_def.getKey())) { string json = map_param[prop_def.getKey()]; if (!string.IsNullOrEmpty(json.Trim())) { prop.set(EbJsonHelper.deserialize <T>(json)); } } return(prop); }
//--------------------------------------------------------------------- void _loadTable(string table_name, List <EbFieldInfo> list_fieldinfo) { EbTable table = new EbTable(); table.Name = table_name; foreach (var i in list_fieldinfo) { switch (i.FieldType) { case EbFieldType.Int: // int { PropDef prop_def = new PropDef(i.FieldName, typeof(int)); table._addPropDef(prop_def); } break; case EbFieldType.Float: // float { PropDef prop_def = new PropDef(i.FieldName, typeof(float)); table._addPropDef(prop_def); } break; case EbFieldType.String: // string { PropDef prop_def = new PropDef(i.FieldName, typeof(string)); table._addPropDef(prop_def); } break; default: break; } } string str_query_select = string.Format("SELECT * FROM {0};", table_name); SQLiteQuery qr; qr = new SQLiteQuery(mSqliteDb, str_query_select); while (qr.Step()) { EbPropSet prop_set = new EbPropSet(); foreach (var i in list_fieldinfo) { bool is_null = qr.IsNULL(i.FieldName); if (is_null) { prop_set._addProp(i.FieldName, null); continue; } switch (i.FieldType) { case EbFieldType.Int: // int { PropDef prop_def = table.getPropDef(i.FieldName); Prop <int> prop = new Prop <int>(prop_def, 0); prop.set(qr.GetInteger(i.FieldName)); prop_set._addProp(i.FieldName, prop); } break; case EbFieldType.Float: // float { PropDef prop_def = table.getPropDef(i.FieldName); Prop <float> prop = new Prop <float>(prop_def, 0f); prop.set((float)qr.GetDouble(i.FieldName)); prop_set._addProp(i.FieldName, prop); } break; case EbFieldType.String: // string { PropDef prop_def = table.getPropDef(i.FieldName); Prop <string> prop = new Prop <string>(prop_def, ""); prop.set(qr.GetString(i.FieldName)); prop_set._addProp(i.FieldName, prop); } break; default: break; } } IProp prop_id = prop_set.getProp("Id"); if (prop_id == null) { EbLog.Error("EbDataMgr1._loadTable() Error! Key=Id not exist, TableName=" + table_name); continue; } Prop <int> p = (Prop <int>)prop_id; prop_set.Id = p.get(); table._addPropSet(prop_set); } qr.Release(); mDb._addTable(table); }
//----------------------------------------------------------------------------- public Prop(PropDef prop_def, T default_value) : base(prop_def) { mValue = default_value; }
//----------------------------------------------------------------------------- public IProp(PropDef prop_def) { mPropDef = prop_def; }
//--------------------------------------------------------------------- internal void _addPropDef(PropDef prop_def) { mMapPropDef[prop_def.getKey()] = prop_def; }