Ejemplo n.º 1
0
        /// <summary>
        ///     Returns the source code for the current class in the specified language.
        /// </summary>
        /// <param name="lang">The language for the return code.</param>
        /// <returns>The Source Code for the class that are currently building.</returns>
        public string GetClassSourceCode(NetLanguage lang)
        {
            var sb = new StringBuilder(100);

            BeginNamespace(lang, sb);

            var attbs = new AttributesBuilder(lang);

            AddAttributesInternal(attbs, lang);
            AddAttributesCode(attbs, lang);

            sb.Append(attbs.GetAttributesCode());

            switch (lang)
            {
            case NetLanguage.VbNet:
                sb.Append(GetVisibility(lang, mVisibility) + GetSealed(lang) + "Class " + mClassName);
                sb.Append(StringHelper.NewLine);
                break;

            case NetLanguage.CSharp:
                sb.Append(GetVisibility(lang, mVisibility) + GetSealed(lang) + "class " + mClassName);
                sb.Append(StringHelper.NewLine);
                sb.Append("{");
                break;
            }

            sb.Append(StringHelper.NewLine);
            sb.Append(StringHelper.NewLine);

            foreach (FieldBuilder field in mFields)
            {
                sb.Append(field.GetFieldCode(lang));
                sb.Append(StringHelper.NewLine);
            }


            sb.Append(StringHelper.NewLine);

            switch (lang)
            {
            case NetLanguage.VbNet:
                sb.Append("End Class");
                break;

            case NetLanguage.CSharp:
                sb.Append("}");
                break;
            }

            EndNamespace(lang, sb);

            return(sb.ToString());
        }
Ejemplo n.º 2
0
        internal string GetFieldCode(NetLanguage lang)
        {
            var sb = new StringBuilder(100);

            var attbs = new AttributesBuilder(lang);

            AddAttributesInternal(attbs, lang);
            AddAttributesCode(attbs, lang);

            sb.Append(attbs.GetAttributesCode());

            var visi        = mVisibility;
            var currentName = mFieldName;

            if (mClassBuilder.GenerateProperties)
            {
                visi        = NetVisibility.Private;
                currentName = "m" + mFieldName;
            }

            switch (lang)
            {
            case NetLanguage.VbNet:
                sb.Append(ClassBuilder.GetVisibility(lang, visi) + currentName + " As " + mFieldType);
                break;

            case NetLanguage.CSharp:
                sb.Append(ClassBuilder.GetVisibility(lang, visi) + mFieldType + " " + currentName + ";");
                break;

            default:
                break;
            }

            sb.Append(StringHelper.NewLine);

            if (mClassBuilder.GenerateProperties)
            {
                sb.Append(StringHelper.NewLine);

                switch (lang)
                {
                case NetLanguage.VbNet:
                    sb.Append("Public Property " + mFieldName + " As " + mFieldType);
                    sb.Append(StringHelper.NewLine);
                    sb.Append("   Get");
                    sb.Append(StringHelper.NewLine);
                    sb.Append("      Return m" + mFieldName);
                    sb.Append(StringHelper.NewLine);
                    sb.Append("   End Get");
                    sb.Append(StringHelper.NewLine);
                    sb.Append("   Set (value As " + mFieldType + ")");
                    sb.Append(StringHelper.NewLine);
                    sb.Append("      m" + mFieldName + " = value");
                    sb.Append(StringHelper.NewLine);
                    sb.Append("   End Set");
                    sb.Append(StringHelper.NewLine);
                    sb.Append("End Property");
                    break;

                case NetLanguage.CSharp:
                    sb.Append("public " + mFieldType + " " + mFieldName);
                    sb.Append(StringHelper.NewLine);
                    sb.Append("{");
                    sb.Append(StringHelper.NewLine);
                    sb.Append("   get { return m" + mFieldName + "; }");
                    sb.Append(StringHelper.NewLine);
                    sb.Append("   set { m" + mFieldName + " = value; }");
                    sb.Append(StringHelper.NewLine);
                    sb.Append("}");
                    break;

                default:
                    break;
                }

                sb.Append(StringHelper.NewLine);
                sb.Append(StringHelper.NewLine);
            }

            return(sb.ToString());
        }
Ejemplo n.º 3
0
        internal string GetFieldCode(NetLanguage lang)
        {
            var sb = new StringBuilder(100);

            var attbs = new AttributesBuilder(lang);

            AddAttributesInternal(attbs, lang);
            AddAttributesCode(attbs, lang);

            sb.Append(attbs.GetAttributesCode());

            var visi = mVisibility;
            var currentName = mFieldName;

            if (mClassBuilder.GenerateProperties)
            {
                visi = NetVisibility.Private;
                currentName = "m" + mFieldName;
            }

            switch (lang)
            {
                case NetLanguage.VbNet:
                    sb.Append(ClassBuilder.GetVisibility(lang, visi) + currentName + " As " + mFieldType);
                    break;
                case NetLanguage.CSharp:
                    sb.Append(ClassBuilder.GetVisibility(lang, visi) + mFieldType + " " + currentName + ";");
                    break;
                default:
                    break;
            }

            sb.Append(StringHelper.NewLine);

            if (mClassBuilder.GenerateProperties)
            {
                sb.Append(StringHelper.NewLine);

                switch (lang)
                {
                    case NetLanguage.VbNet:
                        sb.Append("Public Property " + mFieldName + " As " + mFieldType);
                        sb.Append(StringHelper.NewLine);
                        sb.Append("   Get");
                        sb.Append(StringHelper.NewLine);
                        sb.Append("      Return m" + mFieldName);
                        sb.Append(StringHelper.NewLine);
                        sb.Append("   End Get");
                        sb.Append(StringHelper.NewLine);
                        sb.Append("   Set (value As " + mFieldType + ")");
                        sb.Append(StringHelper.NewLine);
                        sb.Append("      m" + mFieldName + " = value");
                        sb.Append(StringHelper.NewLine);
                        sb.Append("   End Set");
                        sb.Append(StringHelper.NewLine);
                        sb.Append("End Property");
                        break;
                    case NetLanguage.CSharp:
                        sb.Append("public " + mFieldType + " " + mFieldName);
                        sb.Append(StringHelper.NewLine);
                        sb.Append("{");
                        sb.Append(StringHelper.NewLine);
                        sb.Append("   get { return m" + mFieldName + "; }");
                        sb.Append(StringHelper.NewLine);
                        sb.Append("   set { m" + mFieldName + " = value; }");
                        sb.Append(StringHelper.NewLine);
                        sb.Append("}");
                        break;
                    default:
                        break;
                }

                sb.Append(StringHelper.NewLine);
                sb.Append(StringHelper.NewLine);
            }

            return sb.ToString();
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Returns the source code for the current class in the specified language.
        /// </summary>
        /// <param name="lang">The language for the return code.</param>
        /// <returns>The Source Code for the class that are currently building.</returns>
        public string GetClassSourceCode(NetLanguage lang)
        {
            var sb = new StringBuilder(100);

            BeginNamespace(lang, sb);

            var attbs = new AttributesBuilder(lang);

            AddAttributesInternal(attbs, lang);
            AddAttributesCode(attbs, lang);

            sb.Append(attbs.GetAttributesCode());

            switch (lang)
            {
                case NetLanguage.VbNet:
                    sb.Append(GetVisibility(lang, mVisibility) + GetSealed(lang) + "Class " + mClassName);
                    sb.Append(StringHelper.NewLine);
                    break;
                case NetLanguage.CSharp:
                    sb.Append(GetVisibility(lang, mVisibility) + GetSealed(lang) + "class " + mClassName);
                    sb.Append(StringHelper.NewLine);
                    sb.Append("{");
                    break;
            }

            sb.Append(StringHelper.NewLine);
            sb.Append(StringHelper.NewLine);

            foreach (FieldBuilder field in mFields)
            {
                sb.Append(field.GetFieldCode(lang));
                sb.Append(StringHelper.NewLine);
            }


            sb.Append(StringHelper.NewLine);

            switch (lang)
            {
                case NetLanguage.VbNet:
                    sb.Append("End Class");
                    break;
                case NetLanguage.CSharp:
                    sb.Append("}");
                    break;
            }

            EndNamespace(lang, sb);

            return sb.ToString();
        }