Пример #1
0
        /// <summary>
        /// Serialise the FiledBuilder to XML
        /// </summary>
        /// <param name="writer">writer to add XML to</param>
        internal void SaveToXml(XmlHelper writer)
        {
            writer.Writer.WriteStartElement("Field");
            writer.Writer.WriteStartAttribute("Name", "");
            writer.Writer.WriteString(mFieldName);
            writer.Writer.WriteEndAttribute();
            writer.Writer.WriteStartAttribute("Type", "");
            writer.Writer.WriteString(mFieldType);
            writer.Writer.WriteEndAttribute();
            WriteHeaderAttributes(writer);

            Converter.WriteXml(writer);

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

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

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

                writer.Writer.WriteEndElement();
            }

            WriteExtraElements(writer);
            writer.Writer.WriteEndElement();
        }
Пример #2
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() +
                                       "\")");
                }
            }
        }
 /// <summary>
 /// Create a fixed length field of name, length and type
 /// </summary>
 /// <param name="fieldName">Name of the field</param>
 /// <param name="length">Length of field on file</param>
 /// <param name="fieldType">Type of the field</param>
 internal FixedFieldBuilder(string fieldName, int length, Type fieldType) : this(fieldName, length, ClassBuilder.TypeToString(fieldType))
 {
 }