Exemple #1
0
        public override string ToString()
        {
            var okToTruncate = false;

            var comment = Comment;

            if (!String.IsNullOrEmpty(Units))
            {
                comment = String.Format("[{0}]{1}{2}", Units, !String.IsNullOrEmpty(comment) ? " " : "", comment);
            }

            var sb = new StringBuilder();

            if (IsCommentRecord())
            {
                sb.AppendFormat("COMMENT  {0}", Comment);
            }
            else if (String.IsNullOrEmpty(Value) && String.IsNullOrEmpty(comment))
            {
                sb.Append(KeyName);
            }
            else if (ValueType == HeaderValueType.String)
            {
                var delimitedValue = StrCvt.Convert(Value);

                if (KeyName.Length <= 8)
                {
                    sb.AppendFormat("{0,-8}= {1,-19}", KeyName, delimitedValue);
                }
                else
                {
                    sb.AppendFormat("HIERARCH {0} = {1}", KeyName, delimitedValue);

                    okToTruncate = true;
                }
            }
            else
            {
                if (KeyName.Length <= 8)
                {
                    sb.AppendFormat("{0,-8}= {1,19}", KeyName, Value);
                }
                else
                {
                    sb.AppendFormat("HIERARCH {0} = {1}", KeyName, Value);
                }
            }

            if (sb.Length > 80)
            {
                if (okToTruncate)
                {
                    // Here we have a string value so it is OK to truncate the record to 80 characters, including
                    // the closing delimiter.

                    sb.Length = 79;
                    sb.Append("'");
                }
            }
            else if (!String.IsNullOrEmpty(comment) && sb.Length + 4 < 80)                 // Add any comment as long as there is room to at least start it.
            {
                sb.AppendFormat(" / {0}", comment);

                if (sb.Length > 80)
                {
                    sb.Length = 80;
                }
            }

            return(sb.ToString());
        }
Exemple #2
0
 private bool IsStringValue(string value)
 {
     return(StrCvt.IsConvertible(value));
 }