예제 #1
0
        //------------------------------------------------------------------
        public static string GetTypeId(Type tp)
        {
            if (tp == null)
            {
                return("");
            }
            string strId = TypeIdAttribute.GetTypeId(tp);

            if (strId == null)
            {
                strId = tp.ToString();
            }
            return(strId);
        }
예제 #2
0
        /// <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);
        }