/// <summary> /// Obtient toute les valeurs des propriétées déclarées dans la classe (PAR REFLEXION) /// </summary> /// <returns></returns> public static Dictionary <string, object> GetDeclaredValues(this DataPO po) { Dictionary <string, object> dict = new Dictionary <string, object>(); foreach (PropertyInfo prp in APP.CODE.PropertiesTools.GetProperties(po.GetType())) { object value = prp.GetValue(po, new object[] { }); dict.Add(prp.Name, value); } return(dict); }
private List <DATAPO.DataPO> GetAllInternal(DataPO po) { Type typepo = po.GetType(); PropertyInfo[] properties = typepo.GetProperties(BindingFlags.Public | BindingFlags.Instance); List <DATAPO.DataPO> retour = new List <DataPO>(); foreach (PropertyInfo prp in properties) { // Only work with strings //if (prp.DeclaringType != typeof(DATAPO.DataPO)) { continue; } // If not writable then cannot null it; if not readable then cannot check it's value if (!prp.CanWrite || !prp.CanRead) { continue; } //if(prp.) object objval = null; try { objval = prp.GetValue(po, new object[] { }); } catch (Exception) // fnc a revoir { continue; } if (!(objval is DATAPO.DataPO)) { continue; } DATAPO.DataPO value = objval as DATAPO.DataPO; if (value == null) { continue; } //dict.Add(prp.Name, value); retour.Add(value); } return(retour); }
/// <summary> /// Permet de preparer l'objet (notament définir le datarow et son schema) /// C'est nécessaire pour les opérations SQL, ou l'instanciation vide d'un DATAPO /// </summary> /// <param name="po"></param> /// <returns></returns> public static void DefineSchemaPO(this DataPO po, bool allowCache = true) { try { if (po == null) { return; } Type potype = po.GetType(); System.Data.DataTable tableStd = DataPOTools.GetSchemaOnPO(potype, allowCache); // on prend un clone de la table DefineSchemaPO(po, tableStd, true); // voir si il est possible d'améliorer pour ne pas prendre de clone !!! (faire le clone que si il y as modification des colonnes) } catch (Exception ex) { throw new Exception(string.Format("InitalizeDataPo {0}", ex.Message)); } }
/// <summary> /// Sérialiser le Datapo /// </summary> /// <param name="po">Objet racine à sérialiser</param> /// <param name="includeInternalPO">Inclure les sous objets</param> /// <param name="fromProperty">Pour les sérialisations en boucles</param> /// <returns>string sérialiser custom</returns> public static string SerializeDatas(DataPO po, bool includeInternalPO = true, PropertyInfo fromProperty = null) { try { StringBuilder retour = new StringBuilder(); retour.Append("[[$"); System.Data.DataRow rowd = po.GetRow(); string strd = MANIPULATE.DATASET.DataTableTools.SerializeDataRow(rowd); if (!string.IsNullOrEmpty(strd)) { retour.Append("[[!dataxml!]]"); retour.Append(strd); retour.AppendLine(); } if (!includeInternalPO) { return(retour.ToString()); } Type typepo = po.GetType(); PropertyInfo[] properties = typepo.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo propertie in properties) { string strproper = ToDatasXMLProperty(propertie, po); if (string.IsNullOrWhiteSpace(strproper)) { continue; } retour.AppendFormat("[[!{0}!]]", propertie.Name); retour.Append(strproper); retour.AppendLine(); } retour.Append("$]]"); return(retour.ToString()); } catch (Exception ex) { throw new Exception("GetDatasXML" + ex.Message, ex); } }
public DataPO GetOrInstanciateInternalPO(DataPO poOrgn, string propName, bool allowInstanciate = true) //where Tobj : DATA.DATAPO.DataPO, new() { DataPO retour = null; Type poType = poOrgn.GetType(); PropertyInfo poProperty = poType.GetProperty(propName); object poino = poProperty.GetValue(poOrgn, null); if (poino != null) { if (poino is DataPO) { retour = (DataPO)poino; } else { return(null); // erreur dans les types } } if (retour == null) { retour = (DataPO)Activator.CreateInstance(poProperty.PropertyType); } return(retour); }
private static System.Data.DataTable CreateSchemaWithAttributes(DataPO po) { Type potype = po.GetType(); return(CreateSchemaWithAttributes(potype)); }