Beispiel #1
0
        private void WriteEnumerableLabel(TypeDetails details, int shown, int?count, int padding)
        {
            string label;

            if (shown < ENUMERABLE_LIMIT || count == ENUMERABLE_LIMIT)
            {
                label = " (" + shown + " items)";
            }
            else if (count.HasValue)
            {
                label = " (First " + shown + " items of " + count + ")";
            }
            else
            {
                label = " (First " + shown + " items)";
            }
            WriteLabel(details.TypeLabel + label, padding);
            WriteLine();
        }
Beispiel #2
0
        private ColorString GetString(TypeDetails details, object instance)
        {
            if (instance == null)
            {
                return(_Null);
            }

            var typeCode = details.SimpleTypeCode;

            var foreground =
                typeCode == TypeCode.String ? ConsoleColor.Cyan :  // string
                typeCode != TypeCode.Object ? ConsoleColor.White : // primitive
                details.Type.IsClass ? ConsoleColor.Magenta :      // class
                ConsoleColor.Yellow;                               // struct

            return(new ColorString(
                       instance.ToString(),
                       foreground,
                       details.NullableStruct ? ConsoleColor.DarkGreen : ConsoleColor.Black));
        }
Beispiel #3
0
 private void Dump(TypeDetails details, object instance, int padding)
 {
     if (instance == null || details.SimpleTypeCode != TypeCode.Object)
     {
         WritePadding(padding);
         Write(GetString(details, instance));
         WriteLine();
     }
     else if (!details.IsEnumerable)
     {
         DumpMembers(details, instance, padding);
         WriteLine();                 // extra
     }
     else if (details.ItemDetails.SimpleTypeCode != TypeCode.Object)
     {
         DumpSimpleEnumerable(details, instance, padding);
         WriteLine();                 // extra
     }
     else
     {
         DumpComplexEnumerable(details, instance, padding);
         WriteLine();                 // extra
     }
 }
Beispiel #4
0
 private MemberDetails(PropertyInfo pi)
 {
     PropertyInfo = pi;
     Name         = pi.Name;
     TypeDetails  = TypeDetails.Get(pi.PropertyType);
 }
Beispiel #5
0
 private MemberDetails(FieldInfo fi)
 {
     FieldInfo   = fi;
     Name        = fi.Name;
     TypeDetails = TypeDetails.Get(fi.FieldType);
 }
Beispiel #6
0
        private void DumpComplexEnumerable(TypeDetails details, object instance, int padding)
        {
            int?count;
            var items = details.GetEnumerableMemberValues(instance, ENUMERABLE_LIMIT, out count);

            var itemType     = details.ItemDetails;
            int columnCount  = itemType.Members.Length;
            var columnWidths = new int[columnCount];
            int columnIndex;

            ColorString[] row;
            var           allValues = new List <ColorString[]>(items.Count + 1);

            // get the column headings
            columnIndex = 0;
            row         = new ColorString[columnCount];
            foreach (var member in itemType.Members)
            {
                row[columnIndex]          = new ColorString(member.Name, HEADING_FOREGROUND, HEADING_BACKGROUND);
                columnWidths[columnIndex] = member.Name.Length;

                columnIndex++;
            }
            allValues.Add(row);

            // get all the values
            foreach (var item in items)
            {
                if (item == null)
                {
                    allValues.Add(null);
                    continue;
                }

                columnIndex = 0;
                row         = new ColorString[columnCount];
                foreach (var value in item)
                {
                    var cs = GetString(value);
                    row[columnIndex] = cs;
                    if (cs.String.Length > columnWidths[columnIndex])
                    {
                        columnWidths[columnIndex] = cs.String.Length;
                    }

                    columnIndex++;
                }
                allValues.Add(row);
            }


            // echo
            WriteEnumerableLabel(details, items.Count, count, padding);
            padding++;

            int rowCount = 0;

            foreach (var item in allValues)
            {
                WritePadding(padding);
                if (item == null)
                {
                    Write(_Null);
                }
                else
                {
                    columnIndex = 0;
                    foreach (var value in item)
                    {
                        // grab TypeCode but not for headings
                        var typeCode = rowCount == 0 ?
                                       TypeCode.String :
                                       itemType.Members[columnIndex].TypeDetails.SimpleTypeCode;

                        Write(_Separator);
                        WriteFixed(value, columnWidths[columnIndex], typeCode);
                        columnIndex++;
                    }
                }
                WriteLine();
                rowCount++;
            }
        }
 protected MemberDetails(string name, TypeDetails details)
 {
     Name        = name;
     TypeDetails = details;
 }
 public ColumnDetails(DataColumn column) : base(column.ColumnName, TypeDetails.Get(column.DataType))
 {
     DataColumn = column;
 }