public override object GetValeur(object obj, CCacheValeursProprietes cacheValeurs, CRestrictionUtilisateurSurType restriction)
        {
            IApplatisseurProprietes applatisseur = obj as IApplatisseurProprietes;

            if (applatisseur != null)
            {
                obj = applatisseur.GetObjetParDefaut();
            }
            if (m_strCleRestriction == "")
            {
                if (m_champOrigine is CDefinitionProprieteDynamiqueChampCustom)
                {
                    CDbKey       keyChamp = ((CDefinitionProprieteDynamiqueChampCustom)m_champOrigine).DbKeyChamp;
                    CChampCustom champ    = new CChampCustom(CContexteDonneeSysteme.GetInstance());
                    if (champ.ReadIfExists(keyChamp))
                    {
                        m_strCleRestriction = champ.CleRestriction;
                    }
                }
                else if (m_champOrigine != null)
                {
                    m_strCleRestriction = m_champOrigine.NomProprieteSansCleTypeChamp;
                }
            }

            if (restriction != null && m_strCleRestriction != "" && (restriction.GetRestriction(m_strCleRestriction) & ERestriction.Hide) == ERestriction.Hide)
            {
                return(null);
            }

            if (!m_bOptimFaite && obj != null)
            {
                m_bOptimFaite = true;
                if (obj is CObjetDonnee)
                {
                    m_strChampOrigineOptim = "";
                    PropertyInfo info = obj.GetType().GetProperty(m_champOrigine.NomProprieteSansCleTypeChamp);

                    //Il faut absolument stocker le type, car si
                    //Le champ vient d'une interface, tous les éléments ne sont pas forcement
                    //du même type, et ne proviennent pas forcement du même champ
                    m_typeOptim = obj.GetType();

                    if (info != null)
                    {
                        object[] attribs = info.GetCustomAttributes(typeof(AccesDirectInterditAttribute), true);
                        if (attribs.Length == 0)
                        {
                            attribs = info.GetCustomAttributes(typeof(TableFieldPropertyAttribute), true);
                            if (attribs != null && attribs.Length > 0)
                            {
                                m_strChampOrigineOptim = ((TableFieldPropertyAttribute)attribs[0]).NomChamp;
                            }
                        }
                    }
                }
                if (m_strChampOrigineOptim == "")
                {
                    m_optimiseur = CInterpreteurProprieteDynamique.GetOptimiseur(obj.GetType(), m_champOrigine.NomPropriete);
                }
            }
            if (m_strChampOrigineOptim != "" && obj is CObjetDonnee && obj.GetType() == m_typeOptim)
            {
                return(((CObjetDonnee)obj).Row[m_strChampOrigineOptim]);
            }
            else if (m_optimiseur != null)
            {
                return(m_optimiseur.GetValue(obj));
            }
            else
            {
                return(CInterpreteurProprieteDynamique.GetValue(obj, ChampOrigine, cacheValeurs).Data);
            }
        }
示例#2
0
        //----------------------------------------------------------
        /// <summary>
        /// Le data du result contient la valeur de la propriété pour l'objet
        /// </summary>
        /// <param name="objet"></param>
        /// <param name="strPropriete"></param>
        /// <returns></returns>
        public static CResultAErreur GetValue(object objet, string strProprieteComplete, CCacheValeursProprietes cache)
        {
            CResultAErreur          result       = CResultAErreur.True;
            IApplatisseurProprietes applatisseur = objet as IApplatisseurProprietes;

            if (applatisseur != null)
            {
                objet = applatisseur.GetObjetPourPropriete(strProprieteComplete);
            }
            if (cache != null && objet != null)
            {
                object valeur = cache.GetValeurCache(objet, strProprieteComplete);
                if (valeur != null)
                {
                    result.Data = valeur;
                    return(result);
                }
            }
            string[] strProprietes     = strProprieteComplete.Split('.');
            string   strPropriete      = strProprietes[0];
            string   strSuitePropriete = "";

            if (strProprieteComplete.Length > strPropriete.Length)
            {
                strSuitePropriete = strProprieteComplete.Substring(strPropriete.Length + 1);
            }
            string strCleType          = "";
            string strProprieteSansCle = "";

            if (CDefinitionProprieteDynamique.DecomposeNomProprieteUnique(strPropriete, ref strCleType, ref strProprieteSansCle))
            {
                object objetSource = null;
                if (cache != null)
                {
                    objetSource = cache.GetValeurCache(objet, strPropriete);
                }
                if (objetSource == null)
                {
                    strPropriete = strProprieteSansCle;
                    Type tpInterpreteur = null;
                    if (m_tableCleTypeToTypeInterpreteur.TryGetValue(strCleType.ToUpper(), out tpInterpreteur))
                    {
                        IInterpreteurProprieteDynamique interpreteur = Activator.CreateInstance(tpInterpreteur) as IInterpreteurProprieteDynamique;
                        if (interpreteur != null)
                        {
                            result = interpreteur.GetValue(objet, strPropriete);
                            if (!result)
                            {
                                return(result);
                            }
                            objetSource = result.Data;
                            if (result && cache != null)
                            {
                                cache.StockeValeurEnCache(objet, strProprietes[0], objetSource);
                            }
                        }
                    }
                    else
                    {
                        result.EmpileErreur(I.T("Can not find parser for @1|20001", strPropriete));
                        return(result);
                    }
                }
                if (objetSource != null && strSuitePropriete.Length > 0)
                {
                    result = GetValue(objetSource, strSuitePropriete);
                    if (result && cache != null)
                    {
                        cache.StockeValeurEnCache(objet, strProprieteComplete, result.Data);
                    }
                }
                return(result);
            }
            if (m_oldInterpreteur != null)
            {
                result.Data = m_oldInterpreteur.GetValue(objet, strProprieteComplete);
                return(result);
            }
            result.EmpileErreur(I.T("Bad property format (@1)|20000", strPropriete));
            return(result);
        }