Esempio n. 1
0
        public void GenerateCode(EAPModel model)
        {
            FilesComplete.Clear();
            FilesForDb.Clear();
            foreach (var item in model.Classes)
            {
                DictionaryEntry table = (DictionaryEntry)item;

                CodeCompileUnit unit = BuildCodeCUnit(model, table.Value, true);
                if (IsDbSelected)
                {
                    CodeCompileUnit unitDb = BuildCodeCUnit(model, table.Value, false);
                    if (unitDb != null)
                    {
                        FilesForDb.Add(unitDb);
                    }
                }
                if (unit != null)
                {
                    //add it to the list, unless its null
                    FilesComplete.Add(unit);
                }
            }
            if (IsDbSelected)
            {
                CodeCompileUnit unitDb = CreateDBContextClass(model);
                FilesForDb.Add(unitDb);
            }
            //   CreateParentClass(); // ovo treba izbaciti za IdentifiedObject
        }
Esempio n. 2
0
        private void CreateParentClass()
        {
            CodeCompileUnit unit = new CodeCompileUnit();
            //namespace
            CodeNamespace nameSpace = new CodeNamespace("Default_Namespace");

            unit.Namespaces.Add(nameSpace);

            //namespace imports
            nameSpace.Imports.Add(new CodeNamespaceImport("System"));

            //class
            CodeTypeDeclaration file = new CodeTypeDeclaration();

            file.IsClass        = true;
            file.Name           = "IDClass";
            file.TypeAttributes = TypeAttributes.Public;

            //create field
            string          fieldName = "_ID";
            CodeMemberField att       = new CodeMemberField(typeof(string), fieldName);

            att.Attributes = MemberAttributes.Private;
            att.Comments.Add(new CodeCommentStatement("ID used for reference purposes", true));

            file.Members.Add(att);

            //create property
            CodeMemberProperty prop = new CodeMemberProperty();

            prop.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            prop.Type       = new CodeTypeReference(typeof(string));
            prop.Name       = "ID";
            prop.HasGet     = true;
            prop.GetStatements.Add(new CodeSnippetExpression("return this." + fieldName));
            prop.HasSet = true;
            prop.SetStatements.Add(new CodeSnippetExpression("this." + fieldName + " = value"));

            file.Members.Add(prop);

            nameSpace.Types.Add(file);

            FilesComplete.Add(unit);
        }