Example #1
0
 internal override void Pad(List <OutputColumn> columns)
 {
     foreach (var column in columns)
     {
         Formatted.Add("".PadRight(column.Width, Separator));
     }
 }
Example #2
0
 internal override void Format(List <OutputColumn> columns)
 {
     foreach (var column in columns)
     {
         Formatted.Add(column.Caption);
         column.Width = column.Caption.Length;
     }
 }
Example #3
0
        private SortedDictionary <int, string> GetSortedLines <T>(T objectToFlatten)
        {
            SortedDictionary <int, string> lines = new SortedDictionary <int, string>();
            Type      type             = objectToFlatten.GetType();
            Formatted flatten          = (Formatted)type.GetCustomAttribute(typeof(Formatted));
            int       offsetAdjustment = flatten.FromZero ? 0 : 1;

            if (flatten != null)
            {
                IOrderedEnumerable <PropertyInfo> properties = type.GetProperties().Where(p => ((Format)p.GetCustomAttribute(typeof(Format), false))?.Line > 0).OrderBy(p => ((Format)p.GetCustomAttribute(typeof(Format), false))?.Line).ThenBy(p => ((Format)p.GetCustomAttribute(typeof(Format), false))?.Offset);
                foreach (PropertyInfo property in properties)
                {
                    Format flat = (Format)property.GetCustomAttribute(typeof(Format), false);
                    if (!lines.ContainsKey(flat.Line))
                    {
                        lines.Add(flat.Line, string.Empty);
                    }
                    if (flat != null)
                    {
                        if (property.PropertyType.GetCustomAttribute(typeof(Formatted)) != null)
                        {
                            lines[flat.Line] = lines[flat.Line] + GetFlattenedString(GetSortedLines(property.GetValue(objectToFlatten)));
                        }
                        else if (property.PropertyType.IsGenericType && typeof(IEnumerable).IsAssignableFrom(property.PropertyType))
                        {
                            IEnumerable?items       = (IEnumerable)property.GetValue(objectToFlatten);
                            int         lineCounter = 1;
                            foreach (var item in items)
                            {
                                if (lineCounter > 1)
                                {
                                    lines[flat.Line] = lines[flat.Line] + Environment.NewLine;
                                }
                                lines[flat.Line] = lines[flat.Line] + GetFlattenedString(GetSortedLines(item));
                                lineCounter++;
                            }
                        }
                        else
                        {
                            if ((flat.Offset - offsetAdjustment) > lines[flat.Line].Length)
                            {
                                throw new Exceptions.FlattenerException(string.Format("Next offest expected at {0}, but {1} specified.", lines[flat.Line].Length, (flat.Offset - offsetAdjustment)));
                            }
                            else if ((flat.Offset - offsetAdjustment) < lines[flat.Line].Length)
                            {
                                throw new Exceptions.FlattenerException(string.Format("Offest {0} specified, but {1} expected.", (flat.Offset - offsetAdjustment), lines[flat.Line].Length));
                            }
                            else
                            {
                                lines[flat.Line] = lines[flat.Line] + FormatString(property.GetValue(objectToFlatten).ToString(), flat);
                            }
                        }
                    }
                }
            }
            return(lines);
        }
Example #4
0
        internal override void Format(List <OutputColumn> columns)
        {
            for (int i = 0; i < columns.Count; i++)
            {
                var column = columns[i];
                var text   = Values.Count > i?string.Format("{0:" + column.Format + "}", Values[i]) : "";

                Formatted.Add(text);
                column.Width = Math.Max(column.Width, text.Length);
            }
        }
Example #5
0
            public Detail(Currency currency)
            {
                NumericCode = currency.NumericCode.ToString(CultureInfo.InvariantCulture);

                Money integer     = new Money(integral, currency),
                      fraction    = new Money(fractional, currency),
                      bigInteger  = new Money(bigIntegral, currency),
                      bigFraction = new Money(bigFractional, currency);

                Integral      = new Formatted(integer);
                Fractional    = new Formatted(fraction);
                BigIntegral   = new Formatted(bigInteger);
                BigFractional = new Formatted(bigFraction);
            }
Example #6
0
        private void Format()
        {
            String rawString   = "";
            String lineContent = "";
            int    charCount   = 0;

            Raw.ForEach(item => rawString += item);
            List <String> rawList  = new List <String>();
            List <String> rawList1 = rawString.Split('\n').ToList();

            rawList1.ForEach(item => {
                List <String> rawList2 = item.Split(' ').ToList();
                rawList2.ForEach(item2 =>
                {
                    rawList.Add(item2);
                });
            });

            int listCount = rawList.Count;

            rawList.ForEach(word => {
                if (charCount + word.Length > LineWidth)
                {
                    if (lineContent.Length == 0)
                    {
                        lineContent = lineContent + word;
                        Formatted.Add(lineContent);
                        lineContent = "";
                        charCount   = 0;
                    }
                    else
                    {
                        lineContent = lineContent.Remove(lineContent.Length - 1);
                        Formatted.Add(lineContent);
                        if (listCount != 1)
                        {
                            lineContent = "";
                            lineContent = word + " ";
                            charCount   = 0;
                            charCount   = word.Length + 1;
                        }
                        else
                        {
                            Formatted.Add(word);
                        }
                    }
                }
                else
                {
                    charCount += word.Length + 1;
                    if (listCount != 1)
                    {
                        lineContent = lineContent + word + " ";
                    }
                    else
                    {
                        lineContent = lineContent + word;
                        Formatted.Add(lineContent);
                    }
                }
                listCount--;
            });
        }