예제 #1
0
        /// <summary>
        /// Génération de la déclaration de la classe.
        /// </summary>
        /// <param name="w">Writer</param>
        /// <param name="item">Classe à générer.</param>
        private void GenerateClassDeclaration(CSharpWriter w, ModelClass item)
        {
            if (item.Stereotype == Stereotype.Reference)
            {
                w.WriteAttribute(1, "Reference");
            }
            else if (item.Stereotype == Stereotype.Statique)
            {
                w.WriteAttribute(1, "Reference", "true");
            }

            if (!string.IsNullOrEmpty(item.DefaultProperty))
            {
                w.WriteAttribute(1, "DefaultProperty", $@"""{item.DefaultProperty}""");
            }

            if (item.DataContract.IsPersistent && !item.IsView)
            {
                if (_parameters.DbSchema != null)
                {
                    w.WriteAttribute(1, "Table", $@"""{item.DataContract.Name}""", $@"Schema = ""{_parameters.DbSchema}""");
                }
                else
                {
                    w.WriteAttribute(1, "Table", $@"""{item.DataContract.Name}""");
                }
            }

            w.WriteClassDeclaration(item.Name, item.ParentClass?.Name, new List <string>());

            GenerateConstProperties(w, item);
            GenerateConstructors(w, item);
            GenerateProperties(w, item);
            GenerateExtensibilityMethods(w, item);
            w.WriteLine(1, "}");

            if (_parameters.UseTypeSafeConstValues.Value)
            {
                GenerateConstPropertiesClass(w, item);
            }
        }
        /// <summary>
        /// Génération de la déclaration de la classe.
        /// </summary>
        /// <param name="w">Writer</param>
        /// <param name="item">Classe à générer.</param>
        private void GenerateClassDeclaration(CSharpWriter w, ModelClass item)
        {
            if (item.Stereotype == Stereotype.Reference)
            {
                w.WriteAttribute(1, "Reference");
            }
            else if (item.Stereotype == Stereotype.Statique)
            {
                w.WriteAttribute(1, "Reference", "true");
            }

            if (!string.IsNullOrEmpty(item.DefaultProperty))
            {
                w.WriteAttribute(1, "DefaultProperty", $@"""{item.DefaultProperty}""");
            }

            if (item.DataContract.IsPersistent && !item.IsView)
            {
                if (_parameters.DbSchema != null)
                {
                    w.WriteAttribute(1, "Table", $@"""{item.DataContract.Name}""", $@"Schema = ""{_parameters.DbSchema}""");
                }
                else
                {
                    w.WriteAttribute(1, "Table", $@"""{item.DataContract.Name}""");
                }
            }

            ICollection <string> interfaces = new List <string>();

            if (_parameters.IsWithEntityInterface && item.DataContract.IsPersistent)
            {
                if (item.HasPrimaryKey && item.PrimaryKey.Count == 1)
                {
                    string name = item.PrimaryKey.First().Name;
                    string type = item.PrimaryKey.First().DataType;

                    if (name == "Id" && type == "int?")
                    {
                        interfaces.Add("IIdEntity");
                    }
                    else if (name == "Code" && type == "string")
                    {
                        interfaces.Add("ICodeEntity");
                    }
                }

                interfaces.Add("IEntity");
            }

            w.WriteClassDeclaration(item.Name, item.ParentClass?.Name, interfaces);

            GenerateConstProperties(w, item);
            GenerateConstructors(w, item);
            GenerateProperties(w, item);
            GenerateExtensibilityMethods(w, item);
            w.WriteLine(1, "}");

            if (_parameters.UseTypeSafeConstValues.Value)
            {
                GenerateConstPropertiesClass(w, item);
            }
        }