Ejemplo n.º 1
0
        private static void PrintProperties(Printer printer)
        {
            string FormatPropertyValue(object obj)
            {
                var sb = new StringBuilder();

                if (obj != null)
                {
                    sb.Append(obj);
                }

                if (obj is Array array)
                {
                    sb.AppendLine();

                    for (var i = 0; i < array.Length; i++)
                    {
                        sb.Append("  [");
                        sb.Append(i);
                        sb.Append("]: ");
                        sb.Append(array.GetValue(i));

                        if (i < array.Length - 1)
                        {
                            sb.AppendLine();
                        }
                    }
                }

                return(sb.ToString());
            }

            var document = new Document
            {
                Commands = new List <ICommand>()
            };

            foreach (var property in printer.Device.GetType().GetProperties())
            {
                document.Commands.Add(new Line
                {
                    Text = $"{EscapeSequence.Bold()}{property.Name}: {EscapeSequence.Normal}{FormatPropertyValue(property.GetValue(printer.Device))}"
                });
            }

            document.Commands.Add(new FeedAndPaperCut());

            printer.PrintReceipt(document);
        }
Ejemplo n.º 2
0
        private static void PrintProperties(Printer printer)
        {
            var lines = new List <Line>();

            var t = printer.Device.GetType();
            var p = t.GetProperties();

            foreach (var propertyInfo in p)
            {
                lines.Add(new Line
                {
                    Alignment         = Alignment.Left,
                    Text              = $"{EscapeSequence.Bold()}{propertyInfo.Name}: {EscapeSequence.Normal}{Format(propertyInfo.GetValue(printer.Device))}",
                    CharactersPerLine = 56
                });
            }


            printer.ExecuteAll(lines);

            printer.Execute(new FeedAndPaperCut());
        }