/// <summary>
        /// Add attributes to the field at the appropriate spot in the code
        /// </summary>
        /// <param name="attbs">Add attributes to this</param>
        /// <param name="lang">Language to use,  C# of Visual Basic</param>
        internal override void AddAttributesCode(AttributesBuilder attbs, NetLanguage lang)
        {
            if (mFieldLength <= 0)
                throw new BadUsageException("The Length of each field must be grater than 0");
            else
                attbs.AddAttribute("FieldFixedLength("+ mFieldLength.ToString() +")");

            if (mAlignMode != AlignMode.Left)
            {
                if (lang == NetLanguage.CSharp)
                    attbs.AddAttribute("FieldAlign(AlignMode."+ mAlignMode.ToString()+", '"+ mAlignChar.ToString() +"')");
                else if (lang == NetLanguage.VbNet)
                    attbs.AddAttribute("FieldAlign(AlignMode."+ mAlignMode.ToString()+", \""+ mAlignChar.ToString() +"\"c)");
            }
        }
        internal override void AddAttributesCode(AttributesBuilder attbs, NetLanguage leng)
        {
            if (mFieldQuoted == true)
            {
                if (leng == NetLanguage.CSharp)
                {
                    string quoteStr = mQuoteChar.ToString();
                    if (mQuoteChar == '\'') quoteStr = @"\'";

                    attbs.AddAttribute("FieldQuoted('" + quoteStr + "', QuoteMode." + mQuoteMode.ToString()+", MultilineMode." + mQuoteMultiline.ToString() +")");
                }
                else if (leng == NetLanguage.VbNet)
                {
                    string quoteStr = mQuoteChar.ToString();
                    if (mQuoteChar == '"') quoteStr = "\"\"";

                    attbs.AddAttribute("FieldQuoted(\"" + quoteStr + "\"c, QuoteMode." + mQuoteMode.ToString()+", MultilineMode." + mQuoteMultiline.ToString() +")");
                }
            }
        }
 /// <summary>
 /// Add any attributes to source (currently only the delimiter attribute)
 /// </summary>
 /// <param name="attbs">Attributes storage area to add to class</param>
 /// <param name="lang"></param>
 internal override void AddAttributesCode(AttributesBuilder attbs, NetLanguage lang)
 {
     if (mDelimiter == string.Empty)
         throw new BadUsageException("The Delimiter of the DelimiterClassBuilder can't be null or empty.");
     else
         attbs.AddAttribute("DelimitedRecord("+ GetDelimiter(mDelimiter, lang) +")");
 }
Example #4
0
        private void AddAttributesInternal(AttributesBuilder attbs, NetLanguage leng)
        {
            if (mFieldOptional == true)
                attbs.AddAttribute("FieldOptional()");

            if (mFieldIgnored == true)
                attbs.AddAttribute("FieldIgnored()");

            if (mFieldInNewLine == true)
                attbs.AddAttribute("FieldInNewLine()");

            if (mFieldNullValue != null)
            {
                if (mFieldNullValue is string)
                    attbs.AddAttribute("FieldNullValue(\"" + mFieldNullValue.ToString() + "\")");
                else
                {
                    string t = ClassBuilder.TypeToString(mFieldNullValue.GetType());
                    string gt = string.Empty;
                    if (leng == NetLanguage.CSharp)
                        gt = "typeof(" + t + ")";
                    else if (leng == NetLanguage.VbNet)
                        gt = "GetType(" + t + ")";

                    attbs.AddAttribute("FieldNullValue("+ gt +", \""+ mFieldNullValue.ToString() +"\")");
                }
            }

            attbs.AddAttribute(mConverter.GetConverterCode(leng));

            if (mTrimMode != TrimMode.None)
            {
                if (" \t" == mTrimChars)
                    attbs.AddAttribute("FieldTrim(TrimMode."+ mTrimMode.ToString()+")");
                else
                    attbs.AddAttribute("FieldTrim(TrimMode." + mTrimMode.ToString() + ", \"" + mTrimChars.ToString() + "\")");
            }
        }
Example #5
0
        internal string GetFieldCode(NetLanguage lang)
        {
            StringBuilder sb = new StringBuilder(100);

            AttributesBuilder attbs = new AttributesBuilder(lang);

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

            sb.Append(attbs.GetAttributesCode());

            NetVisibility visi = mVisibility;
            string 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();
        }
Example #6
0
 internal abstract void AddAttributesCode(AttributesBuilder attbs, NetLanguage leng);
 /// <summary>
 /// add attributes to the class text
 /// </summary>
 /// <param name="attbs"></param>
 /// <param name="lang"></param>
 internal override void AddAttributesCode(AttributesBuilder attbs, NetLanguage lang)
 {
     attbs.AddAttribute("FixedLengthRecord(FixedMode."+ mFixedMode.ToString()+ ")");
 }
        /// <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)
        {
            ValidateClass();

            StringBuilder sb = new StringBuilder(100);

            BeginNamespace(lang, sb);

            AttributesBuilder attbs = new AttributesBuilder(lang);

            AddAttributesInternal(attbs);
            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();
        }
        private void AddAttributesInternal(AttributesBuilder attbs)
        {
            if (mIgnoreFirstLines != 0)
                attbs.AddAttribute("IgnoreFirst(" + mIgnoreFirstLines.ToString() + ")");

            if (mIgnoreLastLines != 0)
                attbs.AddAttribute("IgnoreLast(" + mIgnoreLastLines.ToString() + ")");

            if (mIgnoreEmptyLines == true)
                attbs.AddAttribute("IgnoreEmptyLines()");

            if (mRecordConditionInfo.Condition != FileHelpers.RecordCondition.None)
                attbs.AddAttribute("ConditionalRecord(RecordCondition." + mRecordConditionInfo.Condition.ToString() + ", \"" + mRecordConditionInfo.Selector + "\")");

            if (mIgnoreCommentInfo.CommentMarker != null && mIgnoreCommentInfo.CommentMarker.Length > 0)
                attbs.AddAttribute("IgnoreCommentedLines(\"" + mIgnoreCommentInfo.CommentMarker + "\", " + mIgnoreCommentInfo.InAnyPlace.ToString().ToLower() + ")");
        }
 internal override void AddAttributesCode(AttributesBuilder attbs)
 {
     if (mDelimiter == string.Empty)
         throw new BadUsageException("The Delimiter of the DelimiterClassBuilder can't be null or empty.");
     else
         attbs.AddAttribute("DelimitedRecord(\""+ mDelimiter +"\")");
 }
Example #11
0
 internal abstract void AddAttributesCode(AttributesBuilder attbs);
Example #12
0
        private void AddAttributesInternal(AttributesBuilder attbs)
        {
            if (mIgnoreFirstLines != 0)
                attbs.AddAttribute("IgnoreFirst(" + mIgnoreFirstLines.ToString() + ")");

            if (mIgnoreLastLines != 0)
                attbs.AddAttribute("IgnoreLast(" + mIgnoreLastLines.ToString() + ")");

            if (mIgnoreEmptyLines)
                attbs.AddAttribute("IgnoreEmptyLines()");

            if (mRecordConditionInfo.Condition != FileHelpers.RecordCondition.None)
                attbs.AddAttribute("ConditionalRecord(RecordCondition." + mRecordConditionInfo.Condition.ToString() + ", \"" + mRecordConditionInfo.Selector + "\")");

            if (!string.IsNullOrEmpty(mIgnoreCommentInfo.CommentMarker))
                attbs.AddAttribute("IgnoreCommentedLines(\"" + mIgnoreCommentInfo.CommentMarker + "\", " + mIgnoreCommentInfo.InAnyPlace.ToString().ToLowerInvariant() + ")");
        }
 /// <summary>
 /// add attributes to the class text
 /// </summary>
 /// <param name="attbs"></param>
 /// <param name="lang"></param>
 internal override void AddAttributesCode(AttributesBuilder attbs, NetLanguage lang)
 {
     attbs.AddAttribute("FixedLengthRecord(FixedMode." + mFixedMode.ToString() + ")");
 }
Example #14
0
        /// <summary>
        /// Add the general attributes to the field
        /// </summary>
        /// <param name="attbs">Attributes added here</param>
        /// <param name="lang">Language  C# or Visual Basic</param>
        private void AddAttributesInternal(AttributesBuilder attbs, NetLanguage lang)
        {
            if (mFieldOptional)
            {
                attbs.AddAttribute("FieldOptional()");
            }

            if (mFieldNotInFile)
            {
                attbs.AddAttribute("FieldNotInFile()");
            }

            if (mFieldValueDiscarded)
            {
                attbs.AddAttribute("FieldValueDiscarded()");
            }

            if (mFieldInNewLine)
            {
                attbs.AddAttribute("FieldInNewLine()");
            }


            if (mFieldNullValue != null)
            {
                if (mFieldNullValue is string)
                {
                    attbs.AddAttribute("FieldNullValue(\"" + mFieldNullValue.ToString() + "\")");
                }
                else
                {
                    string t  = ClassBuilder.TypeToString(mFieldNullValue.GetType());
                    string gt = string.Empty;
                    if (lang == NetLanguage.CSharp)
                    {
                        gt = "typeof(" + t + ")";
                    }
                    else if (lang == NetLanguage.VbNet)
                    {
                        gt = "GetType(" + t + ")";
                    }

                    attbs.AddAttribute("FieldNullValue(" + gt + ", \"" + mFieldNullValue.ToString() + "\")");
                }
            }


            attbs.AddAttribute(mConverter.GetConverterCode(lang));

            if (mTrimMode != TrimMode.None)
            {
                if (" \t" == mTrimChars)
                {
                    attbs.AddAttribute("FieldTrim(TrimMode." + mTrimMode.ToString() + ")");
                }
                else
                {
                    attbs.AddAttribute("FieldTrim(TrimMode." + mTrimMode.ToString() + ", \"" + mTrimChars.ToString() + "\")");
                }
            }
        }
Example #15
0
 /// <summary>
 /// Allow child classes to add attributes at the right spot
 /// </summary>
 /// <param name="attbs">Attributes added here</param>
 /// <param name="lang">Language  C# or Visual Basic</param>
 internal abstract void AddAttributesCode(AttributesBuilder attbs, NetLanguage lang);
Example #16
0
        /// <summary>
        /// Create the field with attributes so that it can be added to the class
        /// </summary>
        /// <param name="lang">Language C# of Visual Basic</param>
        /// <returns>Field as text</returns>
        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());

            NetVisibility visi        = mVisibility;
            string        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());
        }