Exemplo n.º 1
0
        public static CDefinitionMethodeDynamique GetDefinitionMethode(Type tp, string strMethode)
        {
            MethodInfo info = tp.GetMethod(strMethode);

            if (info == null)
            {
                return(null);
            }
            object[] attribs = info.GetCustomAttributes(typeof(DynamicMethodAttribute), true);
            if (attribs.Length == 1)
            {
                DynamicMethodAttribute      attrib  = (DynamicMethodAttribute)attribs[0];
                CTypeResultatExpression     typeRes = CTypeResultatExpression.FromTypeDotNet(info.ReturnType);
                CDefinitionMethodeDynamique def     = new CDefinitionMethodeDynamique(
                    info.Name,
                    info.Name,
                    typeRes,
                    CFournisseurGeneriqueProprietesDynamiques.HasSubProperties(typeRes.TypeDotNetNatif),
                    attrib.Descriptif,
                    attrib.InfosParametres);
                def.Rubrique = I.T("Methods|58");
                return(def);
            }
            return(null);
        }
Exemplo n.º 2
0
        public CDefinitionProprieteDynamique[] GetDefinitionsChamps(CObjetPourSousProprietes objet, CDefinitionProprieteDynamique defParente)
        {
            List <CDefinitionProprieteDynamique> lstProps = new List <CDefinitionProprieteDynamique>();

            if (objet == null)
            {
                return(lstProps.ToArray());
            }
            Type tp = objet.TypeAnalyse;

            if (tp == null)
            {
                return(lstProps.ToArray());
            }

            //Va chercher les propriétés
            foreach (MethodInfo methode in tp.GetMethods())
            {
                object[] attribs = methode.GetCustomAttributes(typeof(DynamicMethodAttribute), true);
                if (attribs.Length == 1)
                {
                    DynamicMethodAttribute  attrib     = (DynamicMethodAttribute)attribs[0];
                    CTypeResultatExpression typeRes    = CTypeResultatExpression.FromTypeDotNet(methode.ReturnType);
                    ParameterInfo[]         parametres = methode.GetParameters();
                    StringBuilder           bl         = new StringBuilder();
                    bl.Append(methode.Name);
                    bl.Append("(");
                    foreach (ParameterInfo info in parametres)
                    {
                        bl.Append(info.Name);
                        bl.Append("; ");
                    }
                    if (parametres.Length > 0)
                    {
                        bl.Remove(bl.Length - 2, 2);
                    }
                    bl.Append(")");
                    CDefinitionProprieteDynamique def = new CDefinitionMethodeDynamique(
                        bl.ToString(),
                        methode.Name,
                        typeRes,
                        CFournisseurGeneriqueProprietesDynamiques.HasSubProperties(typeRes.TypeDotNetNatif),
                        attrib.Descriptif,
                        attrib.InfosParametres);
                    def.Rubrique = I.T("Methods|58");
                    lstProps.Add(def);
                }
            }
            foreach (CMethodeSupplementaire methode in CGestionnaireMethodesSupplementaires.GetMethodsForType(tp))
            {
                CDefinitionProprieteDynamique def = new CDefinitionMethodeDynamique(
                    methode.Name,
                    methode.Name,
                    new CTypeResultatExpression(methode.ReturnType, methode.ReturnArrayOfReturnType),
                    CFournisseurGeneriqueProprietesDynamiques.HasSubProperties(methode.ReturnType));
                def.Rubrique = I.T("Methods|58");
                lstProps.Add(def);
            }
            return(lstProps.ToArray());
        }
 /// //////////////////////////////////////////////////////////////////////
 public CDefinitionProprieteDynamiqueVariableDynamique(IVariableDynamique variable)
     : base(
         variable.Nom,
         variable.IdVariable,
         variable.TypeDonnee,
         CFournisseurGeneriqueProprietesDynamiques.HasSubProperties(variable.TypeDonnee.TypeDotNetNatif),
         false)
 {
     m_variable = variable;
 }
Exemplo n.º 4
0
        public CDefinitionProprieteDynamique[] GetDefinitionsChamps(CObjetPourSousProprietes objet, CDefinitionProprieteDynamique defParente)
        {
            if (objet == null)
            {
                return(new CDefinitionProprieteDynamique[0]);
            }
            List <CDefinitionProprieteDynamique> lst = new List <CDefinitionProprieteDynamique>();
            Type tpRacine = objet.TypeAnalyse;
            Type tp       = objet.TypeAnalyse;

            CDefinitionProprieteDynamique[] defCache = null;
            if (tpRacine != null)
            {
                if (m_cache.TryGetValue(tpRacine, out defCache))
                {
                    return(defCache);
                }
            }
            while (tp != null)
            {
                Dictionary <string, CInfoDynamicFieldAjoute> dic = null;
                if (m_dicTypeToFields.TryGetValue(tp, out dic))
                {
                    foreach (KeyValuePair <string, CInfoDynamicFieldAjoute> pair in dic)
                    {
                        CDefinitionProprieteDynamiqueAjoutee def = new CDefinitionProprieteDynamiqueAjoutee(
                            tp,
                            pair.Key,
                            pair.Value,
                            CFournisseurGeneriqueProprietesDynamiques.HasSubProperties(pair.Value.TypePropriete.TypeDotNetNatif),
                            pair.Value.Rubrique);
                        lst.Add(def);
                    }
                }
                tp = tp.BaseType;
            }
            defCache = lst.ToArray();
            if (tpRacine != null)
            {
                m_cache[tpRacine] = defCache;
            }
            return(defCache);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }