Esempio n. 1
0
    private static string getPropertyText(ProjectClass pClass, ClassVariable classVar, string namSpace,
                                          language lang, CodeGeneration.Format codeFormat, string DAL = "")
    {
        DataType      mDataType             = classVar.ParameterType;
        string        nameWithUnderscore    = "_" + classVar.Name;
        string        nameWithoutUnderScore = classVar.Name;
        StringBuilder retStrB = new StringBuilder();

        retStrB.Append(cg.getMetaDataText(string.Format("Gets or sets the {0} for this {1}.{2} object.",
                                                        nameWithoutUnderScore, pClass.NameSpaceVariable.NameBasedOnID, pClass.Name.Text()),
                                          false, (int)tab.XX, lang, mDataType.Name(), namSpace));
        string propertyAttribute = "";

        if (classVar.IsPropertyXMLIgnored)
        {
            propertyAttribute = cg.GetByLanguage(lang, "<XmlIgnore()> ", "[XmlIgnore]");
        }

        if (cg.isRegularDataType(mDataType.Name()) | DAL.Length == 0)
        {
            retStrB.Append(getPropertyStringForRegularType(classVar, propertyAttribute,
                                                           nameWithoutUnderScore, nameWithUnderscore, lang, codeFormat));
        }
        else
        {
            retStrB.Append(getPropertyStringForDerivedObject(pClass, classVar, propertyAttribute,
                                                             nameWithoutUnderScore, nameWithUnderscore, mDataType, namSpace, DAL, lang, codeFormat));
        }

        return(retStrB.ToString());
    }
Esempio n. 2
0
    private static string getPropertyStringForDerivedObject(ProjectClass pClass, ClassVariable classVar, string propertyAttribute,
                                                            string nameWithoutUnderscore, string nameWithUnderscore, DataType mDataType, string namSpace, string DAL, language lang,
                                                            CodeGeneration.Format codeFormat)
    {
        StringBuilder strB             = new StringBuilder();
        var           nameOfIDVariable = nameWithoutUnderscore + "ID";

        if (lang == language.VisualBasic)
        {
            strB.Append(cg.GetByLanguage(lang,
                                         getPropertyStringForDerivedObjectInVB(nameOfIDVariable, classVar, propertyAttribute,
                                                                               nameWithoutUnderscore, nameWithUnderscore, mDataType),
                                         getPropertyStringForDerivedObjectInCSharp(nameOfIDVariable, classVar, propertyAttribute,
                                                                                   nameWithoutUnderscore, nameWithUnderscore, mDataType)));
        }
        int ID = 0;

        if (pClass.ClassVariables.Count > 0)
        {
            ID = pClass.ClassVariables[pClass.ClassVariables.Count - 1].ID + 1;
        }

        // TODO: Fix this
        if (!classVar.IsList)
        {
            strB.Append(getPropertyText(pClass, new ClassVariable(pClass, nameOfIDVariable,
                                                                  StaticVariables.Instance.GetDataType("Integer"), false, false, false, true, classVar.IsPropertyInherited,
                                                                  classVar.DisplayOnEditPage, classVar.DisplayOnViewPage, ID, true, false, "Integer", -1, "NA"), namSpace, lang, codeFormat, DAL));
        }
        return(strB.ToString());
    }
Esempio n. 3
0
    private static string getProperties(ProjectClass pClass, language lang, CodeGeneration.Format codeFormat)
    {
        StringBuilder retStrB  = new StringBuilder();
        string        namSpace = pClass.NameSpaceVariable.NameBasedOnID;

        foreach (ClassVariable cv in pClass.ClassVariables)
        {
            try {
                if (cv.IsPropertyInherited || cv.ParameterType.IsImage)
                {
                    continue;
                }
                retStrB.AppendLine(getPropertyText(pClass, cv, namSpace, lang, codeFormat, pClass.DALClassVariable.Name));
            } catch (Exception ex) {
                retStrB.AppendLine(string.Format("{3}ERROR: While Adding Variable({0}), the following error occured: " +
                                                 "{1}{3}MSG: {2}{1}", cv.Name, Constants.vbCrLf, ex.Message, cg.getCommentString(lang)));
            }
        }
        return(retStrB.ToString());
    }
Esempio n. 4
0
    private static string getEntireClassInCSharp(ProjectClass pClass, string objName, string namSpace, string Comments,
                                                 string creator, CodeGeneration.Format codeFormat)
    {
        StringBuilder retStrB = new StringBuilder();

        string properties = getProperties(pClass, language.CSharp, codeFormat);

        retStrB.AppendLine("//Created By: " + creator + " (using Code generator)");
        retStrB.AppendLine("//Created On: " + DateTime.Now.ToString());
        retStrB.AppendLine("using System;");
        retStrB.AppendLine("using System.Net;");
        retStrB.AppendLine("using System.Linq;");
        retStrB.AppendLine("using System.Collections.Generic;");
        if (codeFormat == CodeGeneration.Format.MVC)
        {
            retStrB.AppendLine("using System.ComponentModel.DataAnnotations;");
        }
        if (properties.ToLower().Contains("xmlignore"))
        {
            retStrB.AppendLine("using System.Xml.Serialization;");
        }
        retStrB.AppendLine("namespace " + namSpace);
        retStrB.AppendLine("{");
        retStrB.AppendLine(cg.getMetaDataText(Comments, false, (int)tab.XX, language.CSharp));
        retStrB.Append(Strings.Space(4) + "public class " + objName);
        bool overridesBase = false;

        if (pClass.BaseClass != null && !string.IsNullOrEmpty(pClass.BaseClass.Name))
        {
            retStrB.Append(" : " + pClass.BaseClass.Name);
            overridesBase = pClass.BaseClass.Name.ToLower().Contains("databaserecord");
        }
        retStrB.AppendLine();
        retStrB.AppendLine("{");
        retStrB.Append(getCodeBody(objName, pClass, properties, overridesBase, language.CSharp));
        retStrB.AppendLine(Strings.Space((int)tab.X) + "}");
        retStrB.AppendLine("}");

        return(retStrB.ToString());
    }
Esempio n. 5
0
    private static string getPropertyStringForRegularType(ClassVariable clsVar, string propertyAttribute, string nameWithoutUnderScore, string nameWithUnderscore, language lang, CodeGeneration.Format codeFormat)
    {
        StringBuilder strB = new StringBuilder();

        if (codeFormat == CodeGeneration.Format.MVC)
        {
            strB.Append(getMVCMetaData(Strings.Space((int)tab.XX), clsVar, lang));
        }
        if (lang == language.VisualBasic)
        {
            strB.AppendLine(Strings.Space((int)tab.XX) + propertyAttribute + "Public Property " + nameWithoutUnderScore + "() As " + clsVar.ParameterType.Name());
            strB.AppendLine(Strings.Space((int)tab.XXX) + "Get");
            strB.AppendLine(Strings.Space((int)tab.XXXX) + "Return " + nameWithUnderscore);
            strB.AppendLine(Strings.Space((int)tab.XXX) + "End Get");
            strB.AppendLine(Strings.Space((int)tab.XXX) + "Set(ByVal value As " + clsVar.ParameterType.Name() + ")");
            strB.Append(Strings.Space((int)tab.XXXX));
            string trimValue = "";
            if (clsVar.ParameterType.Name().ToLower().CompareTo("string") == 0)
            {
                trimValue = ".Trim()";
            }
            strB.AppendLine(nameWithUnderscore + " = value" + trimValue);
            strB.AppendLine(Strings.Space((int)tab.XXX) + "End Set");
            strB.AppendLine(Strings.Space((int)tab.XX) + "End Property");
        }
        else
        {
            strB.AppendLine(Strings.Space((int)tab.XX) + propertyAttribute + "public " + clsVar.ParameterType.Name(language.CSharp) + " " + nameWithoutUnderScore);
            strB.AppendLine(Strings.Space((int)tab.XX) + "{");
            strB.AppendLine(Strings.Space((int)tab.XXX) + "get");
            strB.AppendLine(Strings.Space((int)tab.XXX) + "{");
            strB.AppendLine(Strings.Space((int)tab.XXXX) + "return " + nameWithUnderscore + ";");
            strB.AppendLine(Strings.Space((int)tab.XXX) + "}");
            strB.AppendLine(Strings.Space((int)tab.XXX) + "set");
            strB.AppendLine(Strings.Space((int)tab.XXX) + "{");
            strB.Append(Strings.Space((int)tab.XXXX));
            string trimValue = "";
            if (clsVar.ParameterType.Name().ToLower().CompareTo("string") == 0)
            {
                trimValue = ".Trim()";
            }
            strB.AppendLine(nameWithUnderscore + " = value" + trimValue + ";");
            strB.AppendLine(Strings.Space((int)tab.XXX) + "}");
            strB.AppendLine(Strings.Space((int)tab.XX) + "}");
        }
        return(strB.ToString());
    }
Esempio n. 6
0
    private static string getEntireClassInVB(ProjectClass pClass, string objName, string namSpace, string Comments, string creator, CodeGeneration.Format codeFormat)
    {
        StringBuilder retStrB    = new StringBuilder();
        string        properties = getProperties(pClass, language.VisualBasic, codeFormat);

        retStrB.AppendLine("'Created By: " + creator + " (using Code generator)");
        retStrB.AppendLine("'Created On: " + DateTime.Now.ToString());
        retStrB.AppendLine("Option Strict On");
        retStrB.AppendLine("Imports Microsoft.VisualBasic");
        retStrB.AppendLine("Imports System.Collections.Generic");
        if (codeFormat == CodeGeneration.Format.MVC)
        {
            retStrB.AppendLine("Imports System.ComponentModel.DataAnnotations");
        }
        if (properties.ToLower().Contains("xmlignore"))
        {
            retStrB.AppendLine("Imports System.Xml.Serialization");
        }
        retStrB.AppendLine("Namespace " + namSpace);
        retStrB.AppendLine(cg.getMetaDataText(Comments, false, (int)tab.XX, language.VisualBasic));
        retStrB.AppendLine(Strings.Space((int)tab.X) + "Public Class " + objName);
        bool overridesBase = false;

        if (pClass.BaseClass != null && !string.IsNullOrEmpty(pClass.BaseClass.Name))
        {
            retStrB.AppendLine(Strings.Space((int)tab.X) + "Inherits " + pClass.BaseClass.Name);
            overridesBase = pClass.BaseClass.Name.ToLower().Contains("databaserecord");
        }
        retStrB.AppendLine("");
        retStrB.Append(getCodeBody(objName, pClass, properties, overridesBase, language.VisualBasic));
        retStrB.AppendLine(Strings.Space((int)tab.X) + "End Class");
        retStrB.AppendLine("End Namespace");

        return(retStrB.ToString());
    }
Esempio n. 7
0
    public static string getEntireClass(ProjectClass pClass, string creator, language lang, CodeGeneration.Format codeFormat, ref List <string> warnings)
    {
        StringBuilder retStrB  = new StringBuilder();
        string        namSpace = "";

        if (pClass.NameSpaceVariable != null)
        {
            namSpace = pClass.NameSpaceVariable.NameBasedOnID;
        }
        string Comments = pClass.Summary;
        // Dim txtProperties As String = txtInVars.Text.Trim
        string dalClassName = pClass.DALClassVariable.Name;
        string objName      = pClass.Name.Capitalized();

        if (objName.Length > 0 & dalClassName.Length > 0)
        {
            if (objName.Length > 0)
            {
                retStrB.Append(cg.GetByLanguage(lang,
                                                getEntireClassInVB(pClass, objName, namSpace, Comments, creator, codeFormat),
                                                getEntireClassInCSharp(pClass, objName, namSpace, Comments, creator, codeFormat)
                                                )
                               );
            }
        }
        else
        {
            if (pClass.Name.Text().Length == 0)
            {
                warnings.Add("Invalid Input: You must provide an Object/Class name.");
            }
            if (dalClassName.Length == 0)
            {
                warnings.Add("Invalid Input: You must provide a Data Access Layer Class name");
            }
        }
        return(retStrB.ToString());
    }