public Image GetImage() { Image img = DynamicClassAttribute.GetImage(TypeDeBase); if (img != null) { Bitmap bmp = new Bitmap(img); Graphics g = Graphics.FromImage(bmp); bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution); img = null; switch (TypeIcone) { case ETypeIconeDynamique.EType: img = Resources.ImagePourIconeDeType; break; } if (img != null) { g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawImage(img, bmp.Width / 2, bmp.Height / 2, bmp.Width / 2, bmp.Height / 2); } g.Dispose(); return(bmp); } return(null); }
/// //////////////////////////////////////////////////////////////// public static string GetNomConvivial(Type tp) { if (tp == null) { return(""); } string strNom = null; if (m_cacheNomsConviviaux.TryGetValue(tp, out strNom)) { return(strNom); } object[] attribs = tp.GetCustomAttributes(typeof(DynamicClassAttribute), false); if (attribs.Length != 0) { DynamicClassAttribute att = attribs[0] as DynamicClassAttribute; if (att != null) { m_cacheNomsConviviaux[tp] = att.NomConvivial; return(att.NomConvivial); } } string[] strNoms = tp.ToString().Split('.'); m_cacheNomsConviviaux[tp] = strNoms[strNoms.Length - 1]; return(strNoms[strNoms.Length - 1]); }
/// <summary> /// Enregistre le type pour éviter d'avoir à le rechercher (optim) /// </summary> /// <param name="tp"></param> public static void RegisterType(Type tp) { m_cache[tp.ToString()] = tp; string strNomConvivial = DynamicClassAttribute.GetNomConvivial(tp); if (strNomConvivial != tp.ToString()) { m_cache[strNomConvivial] = tp; } }
/// //////////////////////////////////////////////////////////////// public static CInfoClasseDynamique[] GetAllDynamicClass(params Type[] typesAttributsNecessaires) { ArrayList lstVals = new ArrayList(); foreach (System.Reflection.Assembly ass in CGestionnaireAssemblies.GetAssemblies()) { try { foreach (Type tp in ass.GetTypes()) { try { object[] attribs = tp.GetCustomAttributes(typeof(DynamicClassAttribute), false); if (attribs != null && attribs.Length == 1) { DynamicClassAttribute dynamicClass = (DynamicClassAttribute)attribs[0]; bool bToAdd = true; foreach (Type tpAttrib in typesAttributsNecessaires) { attribs = tp.GetCustomAttributes(tpAttrib, false); if (attribs == null || attribs.Length == 0) { bToAdd = false; } } if (bToAdd) { lstVals.Add(new CInfoClasseDynamique(tp, dynamicClass.NomConvivial)); } } } catch {} } } catch { System.Console.WriteLine(I.T("Type loading error|30108")); } } lstVals.Sort(new CInfoClassComparer()); return((CInfoClasseDynamique[])lstVals.ToArray(typeof(CInfoClasseDynamique))); }
/// //////////////////////////////////////////////////////////////// public static CInfoClasseDynamique[] GetAllDynamicClassHeritant(params Type[] typesHeritageNecessaires) { ArrayList lstVals = new ArrayList(); foreach (System.Reflection.Assembly ass in CGestionnaireAssemblies.GetAssemblies()) { try { foreach (Type tp in ass.GetTypes()) { try { bool bOk = true; foreach (Type tpHeritant in typesHeritageNecessaires) { if (!tpHeritant.IsAssignableFrom(tp)) { bOk = false; break; } } if (bOk) { lstVals.Add(new CInfoClasseDynamique( tp, DynamicClassAttribute.GetNomConvivial(tp))); } } catch { } } } catch { System.Console.WriteLine(I.T("Type loading error|30108")); } } lstVals.Sort(new CInfoClassComparer()); return((CInfoClasseDynamique[])lstVals.ToArray(typeof(CInfoClasseDynamique))); }
/// <summary> /// Aloue un objet à partir de son type sous forme de texte /// </summary> /// <param name="strTypeURI"></param> /// <param name="parametresConstructeur"></param> /// <returns></returns> public static Type GetType(string strTypeAdr, bool bAvecDynamicClass, bool bAvecTypeId) { if (String.IsNullOrEmpty(strTypeAdr)) { return(null); } string strAss = ""; Type tp = null; string strTypeDemande = strTypeAdr; if (m_cache.TryGetValue(strTypeAdr, out tp)) { return(tp); } if (bAvecTypeId) { tp = TypeIdAttribute.GetType(strTypeAdr); } if (tp != null) { return(tp); } int nPosPipe = strTypeAdr.IndexOf('|'); if (nPosPipe > 0) //Si le nom est composé de assembly|nom de classe { strAss = strTypeAdr.Substring(0, nPosPipe); strTypeAdr = strTypeAdr.Substring(nPosPipe + 1); } string strTypeUpper = strTypeAdr.ToUpper(CultureInfo.InvariantCulture); tp = Type.GetType(strTypeAdr); if (tp == null) { if (!m_cache.TryGetValue(strTypeAdr, out tp) || tp == null) { if (strAss.Length > 0) { try { Assembly ass = Assembly.Load(strAss); if (ass != null) { tp = ass.GetType(strTypeAdr); } } catch { } } if (tp == null) { //Tente d'abord en direct dans les assemblies foreach (System.Reflection.Assembly ass in CGestionnaireAssemblies.GetAssemblies()) { tp = ass.GetType(strTypeAdr); if (tp != null) { break; } } } if (tp == null) { //Si on ne trouve pas en recherche directe, balaie tous les assemblies, et cherche à la main dedans foreach (System.Reflection.Assembly ass in CGestionnaireAssemblies.GetAssemblies()) { foreach (Type type in ass.GetTypes()) { if (type.FullName == strTypeAdr || type.Name == strTypeAdr || (bAvecDynamicClass && DynamicClassAttribute.GetNomConvivial( type).ToUpper(CultureInfo.InvariantCulture) == strTypeUpper)) { tp = type; break; } } if (tp != null) { break; } } } if (tp == null) { //Recherche parmis les types obsolètes if (!m_dicTypesObsoletes.TryGetValue(strTypeAdr, out tp)) { tp = null; } } m_cache[strTypeAdr] = tp; } } m_cache[strTypeDemande] = tp; return(tp); }