Example #1
0
        /// <summary>
        /// Création d'un modèle de type classe
        /// </summary>
        /// <param name="clazz">Type clr de la classe</param>
        /// <param name="createEnum">if set to <c>true</c> [create enum].</param>
        /// <returns></returns>
        private DataType CreateModel(Type clazz, bool createEnum)
        {
            bool          classExists;
            ClassNameInfo nameHelper = new ClassNameInfo(_initialNamespace, clazz.FullName);
            DataType      model      = _layer.AddTypeIfNotExists(nameHelper.Namespace, clazz.Name, createEnum, out classExists);

            CustomAttributeReflector c = new CustomAttributeReflector(clazz);

            if (c.MoveTo(typeof(XmlRootAttribute)))
            {
                model.XmlName       = c.GetPropertyValue <string>("ElementName");
                _layer.XmlNamespace = c.GetPropertyValue <string>("Namespace");
            }

            return(model);
        }
Example #2
0
        /// <summary>
        /// Création d'un modèle de type enum
        /// </summary>
        /// <param name="clazz">Type clr de l'enum</param>
        private void CreateEnumModel(Type clazz)
        {
            DataType obj = CreateModel(clazz, true);

            if (!(obj is Enumeration))
            {
                ServiceLocator.Instance.IDEHelper.ShowMessage(String.Format("The enum type {0} already exists in the model like an entity, the import will be ignored. You can delete it and retry the import.", obj.Name));
                return;
            }

            Enumeration model = obj as Enumeration;

            // Les propriétés de l'enum sont ces valeurs
            foreach (FieldInfo fi in clazz.GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                EnumValue v = new EnumValue(_layer.Store);
                v.Name     = fi.Name;
                v.Type     = fi.FieldType.Name;
                v.Value    = (int)fi.GetRawConstantValue();
                v.HasValue = true;

                CustomAttributeReflector car = new CustomAttributeReflector(fi);
                if (car.MoveTo(typeof(XmlElementAttribute)))
                {
                    v.XmlName = car.GetPropertyValue <string>("ElementName");
                }

                model.Values.Add(v);
            }
        }
Example #3
0
        /// <summary>
        /// Création d'un modèle de type classe
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="clazz">Clr Type initial</param>
        private void CreateEntity(Entity model, Type clazz)
        {
            model.Properties.Clear();

            // Héritage
            if (!(clazz.BaseType.FullName.StartsWith("System.")))
            {
                model.SuperClass = _layer.SoftwareComponent.FindGlobalType(clazz.BaseType.FullName) as Entity;
            }

            // Propriétés de la classe
            foreach (PropertyInfo prop in clazz.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                if (prop.CanRead)
                {
                    string xmlName = "";
                    CustomAttributeReflector car = new CustomAttributeReflector(prop);
                    if (car.MoveTo(typeof(XmlElementAttribute)))
                    {
                        xmlName = car.GetPropertyValue <string>("ElementName");
                    }

                    // Création d'une association
                    if (prop.PropertyType.IsClass && prop.PropertyType.Assembly == clazz.Assembly)
                    {
                        string typeName = GetTypeElement(prop);
                        if (typeName != null)
                        {
                            Entity target = _layer.SoftwareComponent.FindGlobalType(typeName) as Entity;
                            if (target != null)
                            {
                                Association association = model.AddAssociationTo(target);
                                association.SourceRoleName     = prop.Name;
                                association.SourceMultiplicity = IsListe(prop.PropertyType) ? Multiplicity.OneMany : Multiplicity.One;
                                association.XmlName            = xmlName;
                                continue;
                            }
                        }

                        typeName = "$error:unable to determine the type.";
                    }

                    // Création d'un attribut
                    DSLFactory.Candle.SystemModel.Property p = new DSLFactory.Candle.SystemModel.Property(_layer.Store);
                    p.Type = prop.PropertyType.FullName;
                    p.Name = prop.Name;
                    //p.IsPrimitive = IsTypePrimitive(prop.PropertyType);
                    p.XmlName = xmlName;
                    model.Properties.Add(p);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Détermine le type de l'élément d'une liste
        /// </summary>
        /// <param name="prop">Propriété</param>
        /// <returns></returns>
        private string GetTypeElement(PropertyInfo prop)
        {
            Type t = prop.PropertyType;

            if (t.IsGenericType)
            {
                // TODO si il y en a plusieurs
                Type[] args = t.GetGenericArguments();
                return(args[0].FullName);
            }
            else
            {
                if (IsListe(t))
                {
                    t = t.GetElementType();
                    if (t != null && t != typeof(object))
                    {
                        return(t.FullName);
                    }
                }
                else
                {
                    return(t.FullName);
                }
            }

            CustomAttributeReflector car = new CustomAttributeReflector(prop);

            if (car.MoveTo(typeof(XmlArrayItemAttribute)))
            {
                return(car.GetPropertyValue <Type>("Type").FullName);
            }

            // TODO erreur impossible de déterminer le type
            return(null);
        }