Defines the location and width of a column in a fixed-length record.
コード例 #1
0
 /// <summary>
 /// Adds a column to the schema, using the given definition to define it.
 /// </summary>
 /// <param name="definition">The definition of the column to add.</param>
 /// <param name="window">Describes the column</param>
 /// <returns>The current schema.</returns>
 public FixedLengthSchema AddColumn(IColumnDefinition definition, Window window)
 {
     if (window == null)
     {
         throw new ArgumentNullException("window");
     }
     AddColumnBase(definition);
     windows.Add(window);
     totalWidth += window.Width;
     return this;
 }
コード例 #2
0
 private string fitWidth(Window window, string value)
 {
     if (value == null)
     {
         value = String.Empty;
     }
     if (value.Length > window.Width)
     {
         return getTruncatedValue(value, window);
     }
     else if (value.Length < window.Width)
     {
         return getPaddedValue(value, window);
     }
     else
     {
         return value;
     }
 }
コード例 #3
0
 private string getTruncatedValue(string value, Window window)
 {
     OverflowTruncationPolicy policy = window.TruncationPolicy ?? options.TruncationPolicy;
     if (policy == OverflowTruncationPolicy.TruncateLeading)
     {
         int start = value.Length - window.Width;  // take characters on the end
         return value.Substring(start, window.Width);
     }
     else
     {
         return value.Substring(0, window.Width);
     }
 }
コード例 #4
0
 private string getPaddedValue(string value, Window window)
 {
     if (window.Alignment == FixedAlignment.LeftAligned)
     {
         return value.PadRight(window.Width, window.FillCharacter ?? options.FillCharacter);
     }
     else
     {
         return value.PadLeft(window.Width, window.FillCharacter ?? options.FillCharacter);
     }
 }