Exemplo n.º 1
0
        private void AddAttributesInternal(AttributesBuilder attbs, NetLanguage leng)
        {
            if (mFieldOptional)
            {
                attbs.AddAttribute("FieldOptional()");
            }

            if (mFieldIgnored)
            {
                attbs.AddAttribute("FieldIgnored()");
            }

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


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

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


            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 + "\")");
                }
            }
        }
Exemplo n.º 2
0
        internal void SaveToXml(XmlHelper writer)
        {
            writer.mWriter.WriteStartElement("Field");
            writer.mWriter.WriteStartAttribute("Name", "");
            writer.mWriter.WriteString(mFieldName);
            writer.mWriter.WriteEndAttribute();
            writer.mWriter.WriteStartAttribute("Type", "");
            writer.mWriter.WriteString(mFieldType);
            writer.mWriter.WriteEndAttribute();
            WriteHeaderAttributes(writer);

            Converter.WriteXml(writer);

            writer.WriteElement("Visibility", Visibility.ToString(), "Public");
            writer.WriteElement("FieldIgnored", FieldIgnored);
            writer.WriteElement("FieldOptional", FieldOptional);
            writer.WriteElement("FieldInNewLine", FieldInNewLine);
            writer.WriteElement("TrimChars", TrimChars, " \t");
            writer.WriteElement("TrimMode", TrimMode.ToString(), "None");

            if (FieldNullValue != null)
            {
                writer.mWriter.WriteStartElement("FieldNullValue");
                writer.mWriter.WriteStartAttribute("Type", "");
                writer.mWriter.WriteString(mFieldNullValue.GetType().FullName);
                writer.mWriter.WriteEndAttribute();

                writer.mWriter.WriteString(mFieldNullValue.ToString());

                writer.mWriter.WriteEndElement();
            }

            WriteExtraElements(writer);
            writer.mWriter.WriteEndElement();
        }
Exemplo n.º 3
0
        private String TrimString(string extractedString)
        {
            switch (TrimMode)
            {
            case TrimMode.None:
                return(extractedString);

            case TrimMode.Both:
                return(extractedString.Trim());

            case TrimMode.Left:
                return(extractedString.TrimStart());

            case TrimMode.Right:
                return(extractedString.TrimEnd());

            default:
                throw new Exception("Trim mode invalid in FieldBase.TrimString -> " + TrimMode.ToString());
            }
        }
Exemplo n.º 4
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 (mFieldHidden)
            {
                attbs.AddAttribute("FieldHidden()");
            }

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

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

            if (mFieldNotEmpty)
            {
                attbs.AddAttribute("FieldNotEmpty()");
            }

            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() +
                                       "\")");
                }
            }
        }
Exemplo n.º 5
0
        public void FillFieldDefinition(NetLanguage leng, StringBuilder sb, bool properties)
        {
            AddMainAttributes(leng, sb);

            if (TrimMode != TrimMode.None)
            {
                switch (leng)
                {
                case NetLanguage.VbNet:
                    sb.Append(IndentString);
                    sb.AppendLine("<FieldTrim(TrimMode." + TrimMode.ToString() + ")> ");
                    break;

                case NetLanguage.CSharp:
                    sb.Append(IndentString);
                    sb.AppendLine("[FieldTrim(TrimMode." + TrimMode.ToString() + ")]");
                    break;

                default:
                    break;
                }
            }

            if (mIsOptional == true)
            {
                switch (leng)
                {
                case NetLanguage.VbNet:
                    sb.Append(IndentString);
                    sb.AppendLine("<FieldOptional()> _");
                    break;

                case NetLanguage.CSharp:
                    sb.Append(IndentString);
                    sb.AppendLine("[FieldOptional()]");
                    break;

                default:
                    break;
                }
            }

            if (sb.ToString(sb.Length - 2, 2) != Environment.NewLine)
            {
                sb.AppendLine();
            }
            sb.Append(IndentString);


            string visi = EnumHelper.GetVisibility(leng, mVisibility);

            string usedname;

            usedname = this.Name;

            if (properties)
            {
                usedname = "m" + this.Name;
                visi     = EnumHelper.GetVisibility(leng, NetVisibility.Private);
            }

            switch (leng)
            {
            case NetLanguage.VbNet:
                sb.AppendLine(visi + " " + usedname + " As " + this.Type);
                break;

            case NetLanguage.CSharp:
                sb.AppendLine(visi + " " + this.Type + " " + usedname + ";");
                break;

            default:
                break;
            }

            sb.AppendLine();
        }