|
2 | 2 | using Garyon.Extensions; |
3 | 3 | using Garyon.Reflection; |
4 | 4 | using Microsoft.CodeAnalysis; |
5 | | -using Syndiesis.ColorHelpers; |
6 | 5 | using Syndiesis.Controls.AnalysisVisualization; |
7 | 6 | using Syndiesis.Controls.Inlines; |
8 | 7 | using Syndiesis.InternalGenerators.Core; |
|
19 | 18 |
|
20 | 19 | namespace Syndiesis.Core.DisplayAnalysis; |
21 | 20 |
|
22 | | -using static System.Net.Mime.MediaTypeNames; |
23 | 21 | using AnalysisTreeListNode = UIBuilder.AnalysisTreeListNode; |
24 | 22 | using AnalysisTreeListNodeLine = UIBuilder.AnalysisTreeListNodeLine; |
25 | 23 | using ComplexGroupedRunInline = ComplexGroupedRunInline.Builder; |
@@ -787,39 +785,26 @@ private static bool IsInteger(object value) |
787 | 785 | protected ImmutableArray<RunOrGrouped> IntegerValueRuns(object value) |
788 | 786 | { |
789 | 787 | var info = IntegerInfo.Create(value); |
790 | | - |
791 | | - var text = value.ToString()!; |
792 | | - var textRun = Run(text, CommonStyles.RawValueBrush); |
793 | | - var hexInline = CreateHexRunGroup(ref info); |
794 | | - var binaryInline = CreateBinaryRunGroup(ref info); |
795 | 788 | return |
796 | 789 | [ |
797 | | - new SingleRunInline(textRun), |
| 790 | + SingleRun(value.ToString()!, ColorizationStyles.NumericLiteralBrush), |
798 | 791 | CreateLargeSplitterRun(), |
799 | | - hexInline, |
| 792 | + CreateHexRunGroup(ref info), |
800 | 793 | CreateLargeSplitterRun(), |
801 | | - binaryInline, |
| 794 | + CreateBinaryRunGroup(ref info), |
802 | 795 | ]; |
803 | 796 | } |
804 | 797 |
|
805 | 798 | private static ComplexGroupedRunInline CreateHexRunGroup( |
806 | 799 | ref readonly IntegerInfo info) |
807 | 800 | { |
808 | | - var value = info.ValueBits; |
809 | | - var size = info.ByteSize; |
810 | | - |
811 | | - // TODO: Create the value strings |
812 | | - return CreateAlternativeNumericGroup("0x", "3412431"); |
| 801 | + return CreateAlternativeNumericGroup("0x", HexIntegerWriter.Write(info, 4)); |
813 | 802 | } |
814 | 803 |
|
815 | 804 | private static ComplexGroupedRunInline CreateBinaryRunGroup( |
816 | 805 | ref readonly IntegerInfo info) |
817 | 806 | { |
818 | | - var value = info.ValueBits; |
819 | | - var size = info.ByteSize; |
820 | | - |
821 | | - // TODO: Create the value strings |
822 | | - return CreateAlternativeNumericGroup("0b", "3412431"); |
| 807 | + return CreateAlternativeNumericGroup("0b", BinaryIntegerWriter.Write(info, 4)); |
823 | 808 | } |
824 | 809 |
|
825 | 810 | private static ComplexGroupedRunInline CreateAlternativeNumericGroup( |
@@ -1683,88 +1668,3 @@ public NodeTypeDisplay ThrowsExceptionDisplay |
1683 | 1668 | => new(CommonTypes.ThrowsException, ThrowsColor); |
1684 | 1669 | } |
1685 | 1670 | } |
1686 | | - |
1687 | | -/// <summary> |
1688 | | -/// Contains information about an integer value that was derived from an object. |
1689 | | -/// </summary> |
1690 | | -/// <param name="Value">The original value as an object as it was retrieved.</param> |
1691 | | -/// <param name="ValueBits">The bits of the integer value in a 64-bit integer.</param> |
1692 | | -/// <param name="ByteSize">The number of bytes the integer has.</param> |
1693 | | -/// <remarks> |
1694 | | -/// This only supports up to <see cref="UInt64"/>. Larger integers are not |
1695 | | -/// natively implemented and are thus ignored. |
1696 | | -/// </remarks> |
1697 | | -internal readonly record struct IntegerInfo( |
1698 | | - object Value, |
1699 | | - ulong ValueBits, |
1700 | | - int ByteSize) |
1701 | | -{ |
1702 | | - public TypeCode TypeCode => Value.GetType().GetTypeCode(); |
1703 | | - |
1704 | | - public static IntegerInfo Create(object value) |
1705 | | - { |
1706 | | - switch (value.GetType().GetTypeCode()) |
1707 | | - { |
1708 | | - case TypeCode.SByte: |
1709 | | - { |
1710 | | - var @sbyte = (sbyte)value; |
1711 | | - var @byte = unchecked((byte)@sbyte); |
1712 | | - ulong bits = @byte; |
1713 | | - return new IntegerInfo(value, bits, sizeof(sbyte)); |
1714 | | - } |
1715 | | - case TypeCode.Byte: |
1716 | | - { |
1717 | | - var @byte = (byte)value; |
1718 | | - ulong bits = @byte; |
1719 | | - return new IntegerInfo(value, bits, sizeof(byte)); |
1720 | | - } |
1721 | | - |
1722 | | - case TypeCode.Int16: |
1723 | | - { |
1724 | | - var @short = (short)value; |
1725 | | - var @ushort = unchecked((ushort)@short); |
1726 | | - ulong bits = @ushort; |
1727 | | - return new IntegerInfo(value, bits, sizeof(short)); |
1728 | | - } |
1729 | | - case TypeCode.UInt16: |
1730 | | - { |
1731 | | - var @ushort = (ushort)value; |
1732 | | - ulong bits = @ushort; |
1733 | | - return new IntegerInfo(value, bits, sizeof(ushort)); |
1734 | | - } |
1735 | | - |
1736 | | - case TypeCode.Int32: |
1737 | | - { |
1738 | | - var @int = (int)value; |
1739 | | - var @uint = unchecked((uint)@int); |
1740 | | - ulong bits = @uint; |
1741 | | - return new IntegerInfo(value, bits, sizeof(int)); |
1742 | | - } |
1743 | | - case TypeCode.UInt32: |
1744 | | - { |
1745 | | - var @uint = (uint)value; |
1746 | | - ulong bits = @uint; |
1747 | | - return new IntegerInfo(value, bits, sizeof(uint)); |
1748 | | - } |
1749 | | - |
1750 | | - case TypeCode.Int64: |
1751 | | - { |
1752 | | - var @long = (long)value; |
1753 | | - var @ulong = unchecked((ulong)@long); |
1754 | | - ulong bits = @ulong; |
1755 | | - return new IntegerInfo(value, bits, sizeof(long)); |
1756 | | - } |
1757 | | - case TypeCode.UInt64: |
1758 | | - { |
1759 | | - var @ulong = (ulong)value; |
1760 | | - ulong bits = @ulong; |
1761 | | - return new IntegerInfo(value, bits, sizeof(ulong)); |
1762 | | - } |
1763 | | - } |
1764 | | - |
1765 | | - throw new NotSupportedException("The object type is not supported."); |
1766 | | - } |
1767 | | - |
1768 | | - // TODO: Create hex representation |
1769 | | - // TODO: Create binary representation |
1770 | | -} |
0 commit comments