Ejemplo n.º 1
0
        /// /////////////////////////////////////////////////
        /// Le data du result contient l'expression
        protected override CResultAErreur GetExpressionChamp(string strChamp)
        {
            CDefinitionProprieteDynamique definitionChamp = null;
            CResultAErreur result = CResultAErreur.True;

            //Est-ce une constante dynamique ?
            foreach (IFournisseurConstantesDynamiques fournisseur in m_lstFournisseursExpressionsDynamiques)
            {
                IExpression constante = fournisseur.GetConstante(strChamp);
                if (constante != null)
                {
                    result.Data = constante;
                    return(result);
                }
            }

            if (m_contexteAnalyse.FournisseurProprietes == null)
            {
                result.EmpileErreur(I.T("The property supplier parser cannot recognize the fields|143"));
                return(result);
            }
            else
            {
                if (!IsAnalyseExpressionObjet())
                {
                    string strNomUpper = strChamp.ToUpper();
                    foreach (CDefinitionProprieteDynamique def in m_contexteAnalyse.GetDefinitionsChamps(m_contexteAnalyse.ObjetAnalyse))
                    {
                        if (def.Nom.ToUpper() == strNomUpper || def.NomPropriete.ToUpper() == strNomUpper)
                        {
                            definitionChamp = def;
                            break;
                        }
                    }
                }
                if (definitionChamp == null)
                {
                    definitionChamp = m_contexteAnalyse.GetVariable(strChamp);
                    if (definitionChamp == null)
                    {
                        //Définition temporaire, elle n'existe pas dans le type de base
                        definitionChamp = new CDefinitionProprieteDynamiqueDotNet(strChamp, strChamp, null, false, true, "");
                    }
                }
                result.Data = new C2iExpressionChamp(definitionChamp);
                return(result);
            }
        }
Ejemplo n.º 2
0
        //----------------------------------------------------
        public static CDefinitionProprieteDynamiqueDotNet GetDefinition(Type tp, string strNomPropriete)
        {
            PropertyInfo info = tp.GetProperty(strNomPropriete);

            if (info == null)
            {
                return(null);
            }
            object[] attrs           = info.GetCustomAttributes(typeof(DynamicFieldAttribute), true);
            string   strNomConvivial = strNomPropriete;
            string   strRubrique     = "";

            if (attrs.Length > 0)
            {
                strNomPropriete = ((DynamicFieldAttribute)attrs[0]).NomConvivial;
                strRubrique     = ((DynamicFieldAttribute)attrs[0]).Rubrique;
            }
            Type tpProp   = info.PropertyType;
            bool bIsArray = tpProp.IsArray;

            if (bIsArray)
            {
                tpProp = tpProp.GetElementType();
            }
            bool bHasSubProprietes = CFournisseurGeneriqueProprietesDynamiques.HasSubProperties(tpProp);
            bool bReadOnly         = info.GetSetMethod() == null;
            CDefinitionProprieteDynamiqueDotNet def = new CDefinitionProprieteDynamiqueDotNet(
                strNomConvivial,
                info.Name,
                new CTypeResultatExpression(tpProp, bIsArray),
                bHasSubProprietes,
                bReadOnly,
                strRubrique);

            return(def);
        }
Ejemplo n.º 3
0
        public CDefinitionProprieteDynamique[] GetDefinitionsChamps(
            CObjetPourSousProprietes objet,
            CDefinitionProprieteDynamique defParente)
        {
            if (objet == null)
            {
                return(new CDefinitionProprieteDynamique[0]);
            }
            Type tp = objet.TypeAnalyse;

            if (tp == null)
            {
                return(new CDefinitionProprieteDynamique[0]);
            }
            CDefinitionProprieteDynamique[] defCache = null;
            if (m_cache.TryGetValue(tp, out defCache))
            {
                return(defCache);
            }
            List <CDefinitionProprieteDynamique> lstDefs = new List <CDefinitionProprieteDynamique>();

            Dictionary <string, PropertyInfo> dicInfos = new Dictionary <string, PropertyInfo>();

            foreach (PropertyInfo info in tp.GetProperties())
            {
                object[] attribs = info.GetCustomAttributes(typeof(DynamicFieldAttribute), true);
                if (attribs.Length == 0)
                {
                    attribs = info.GetCustomAttributes(typeof(DynamicChildsAttribute), true);
                }
                if (attribs.Length == 1)
                {
                    dicInfos[info.Name] = info;
                }
            }
            foreach (Type tpInterface in tp.GetInterfaces())
            {
                foreach (PropertyInfo info in tpInterface.GetProperties())
                {
                    if (!dicInfos.ContainsKey(info.Name))
                    {
                        object[] attribs = info.GetCustomAttributes(typeof(DynamicFieldAttribute), true);
                        if (attribs.Length == 0)
                        {
                            attribs = info.GetCustomAttributes(typeof(DynamicChildsAttribute), true);
                        }
                        if (attribs.Length == 1)
                        {
                            dicInfos[info.Name] = info;
                        }
                    }
                }
            }

            //Proprietes
            foreach (PropertyInfo info in dicInfos.Values)
            {
                object[] attribs = info.GetCustomAttributes(typeof(DynamicFieldAttribute), true);
                if (attribs.Length == 1)
                {
                    DynamicFieldAttribute attrib = (DynamicFieldAttribute)attribs[0];
                    bool bReadOnly = info.GetSetMethod() == null;
                    Type tpProp    = info.PropertyType;
                    bool bIsArray  = tpProp.IsArray;
                    if (bIsArray)
                    {
                        tpProp = tpProp.GetElementType();
                    }
                    bool bHasSubProprietes            = CFournisseurGeneriqueProprietesDynamiques.HasSubProperties(tpProp);
                    CDefinitionProprieteDynamique def = new CDefinitionProprieteDynamiqueDotNet(
                        attrib.NomConvivial,
                        info.Name,
                        new CTypeResultatExpression(tpProp, bIsArray),
                        bHasSubProprietes,
                        bReadOnly,
                        attrib.Rubrique);
                    lstDefs.Add(def);
                }
                attribs = info.GetCustomAttributes(typeof(DynamicChildsAttribute), true);
                {
                    if (attribs.Length == 1)
                    {
                        DynamicChildsAttribute        attrib = (DynamicChildsAttribute)attribs[0];
                        CDefinitionProprieteDynamique def    = new CDefinitionProprieteDynamiqueDotNet(
                            attrib.NomConvivial,
                            info.Name,
                            new CTypeResultatExpression(attrib.TypeFils, true),
                            true,
                            true,
                            attrib.Rubrique);
                        lstDefs.Add(def);
                    }
                }
            }
            defCache    = lstDefs.ToArray();
            m_cache[tp] = defCache;
            return(defCache);
        }