/// <summary> /// 获得表属性 /// </summary> /// <typeparam name="T">类型</typeparam> /// <returns>表属性</returns> public static SQLiteTableMapAttribute GetTableAttribute <T>() where T : AbsStrayFogSQLiteEntity { int key = typeof(T).GetHashCode(); int propertyKey = 0; Type entityType = typeof(T); SQLiteTableMapAttribute tableAttribute = null; SQLiteFieldTypeAttribute fieldAttribute = null; //SQLiteTableMapAttribute if (!msSQLiteTableMapAttributeMaping.ContainsKey(key)) { tableAttribute = typeof(T).GetFirstAttribute <SQLiteTableMapAttribute>(); msSQLiteTableMapAttributeMaping.Add(key, tableAttribute); } else { tableAttribute = msSQLiteTableMapAttributeMaping[key]; } //SQLiteFieldTypeAttribute if (!msEntitySQLitePropertySQLiteFieldTypeAttributeMaping.ContainsKey(tableAttribute.id)) { msEntitySQLitePropertySQLiteFieldTypeAttributeMaping.Add(tableAttribute.id, new Dictionary <int, SQLiteFieldTypeAttribute>()); } //PropertyInfo if (!msEntityPropertyInfoMaping.ContainsKey(tableAttribute.id)) { msEntityPropertyInfoMaping.Add(tableAttribute.id, new Dictionary <int, PropertyInfo>()); PropertyInfo[] pps = entityType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.DeclaredOnly); if (pps != null && pps.Length > 0) { foreach (PropertyInfo p in pps) { propertyKey = p.Name.UniqueHashCode(); fieldAttribute = p.GetFirstAttribute <SQLiteFieldTypeAttribute>(); if (fieldAttribute != null) { if (!msEntityPropertyInfoMaping[tableAttribute.id].ContainsKey(propertyKey)) { msEntityPropertyInfoMaping[tableAttribute.id].Add(propertyKey, p); } if (!msEntitySQLitePropertySQLiteFieldTypeAttributeMaping[tableAttribute.id].ContainsKey(propertyKey)) { msEntitySQLitePropertySQLiteFieldTypeAttributeMaping[tableAttribute.id].Add(propertyKey, fieldAttribute); } } } } } //SQLiteHelper if (StrayFogRunningPool.runningSetting.isUseSQLite) { if (!msStrayFogSQLiteHelperMaping.ContainsKey(tableAttribute.dbSQLiteKey)) { if (StrayFogRunningPool.runningSetting.isUseAssetBundle) { msStrayFogSQLiteHelperMaping.Add(tableAttribute.dbSQLiteKey, new StrayFogSQLiteHelper(StrayFogRunningPool.runningSetting.GetSQLiteConnectionString(tableAttribute.dbSQLiteAssetBundleName))); } else { msStrayFogSQLiteHelperMaping.Add(tableAttribute.dbSQLiteKey, new StrayFogSQLiteHelper(StrayFogRunningPool.runningSetting.GetSQLiteConnectionString(tableAttribute.dbSQLitePath))); } } } return(tableAttribute); }
/// <summary> /// 获得实体属性值从实体属性值到XLS列值 /// </summary> /// <param name="_entity">实体</param> /// <param name="_propertyInfo">属性信息</param> /// <param name="_fieldAttribute">字段属性</param> /// <returns>转换后的列值</returns> public static object GetValueFromEntityPropertyToXlsColumn(object _entity, PropertyInfo _propertyInfo, SQLiteFieldTypeAttribute _fieldAttribute) { object srcValue = _propertyInfo.GetValue(_entity, null); ArrayList arrayListOne = null; ArrayList arrayListTwo = null; List <string> arrayValueOne = null; List <string> arrayValueTwo = null; switch (_fieldAttribute.arrayDimension) { case enSQLiteDataTypeArrayDimension.TwoDimensionArray: arrayListOne = new ArrayList((ICollection)srcValue); arrayValueOne = new List <string>(); for (int i = 0; i < arrayListOne.Count; i++) { arrayListTwo = new ArrayList((ICollection)arrayListOne[i]); arrayValueTwo = new List <string>(); for (int k = 0; k < arrayListTwo.Count; k++) { arrayValueTwo.Add(OnGetValueFromEntityToXls(arrayListTwo[k], _fieldAttribute.dataType).ToString()); } arrayValueOne.Add(string.Join(msrElementSeparate[0], arrayValueTwo.ToArray())); } srcValue = string.Join(msrArraySeparate[0], arrayValueOne.ToArray()); break; case enSQLiteDataTypeArrayDimension.OneDimensionArray: arrayListOne = new ArrayList((ICollection)srcValue); arrayValueOne = new List <string>(); for (int i = 0; i < arrayListOne.Count; i++) { arrayValueOne.Add(OnGetValueFromEntityToXls(arrayListOne[i], _fieldAttribute.dataType).ToString()); } srcValue = string.Join(msrArraySeparate[0], arrayValueOne.ToArray()); break; default: srcValue = OnGetValueFromEntityToXls(srcValue, _fieldAttribute.dataType); break; } return(srcValue.ToString()); }