Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TryFormat() [3/3]

unsafe bool System.Guid.TryFormat ( Span< char > destination,
out int charsWritten,
ReadOnlySpan< char > format = default(ReadOnlySpan<char>) )
inline

Definition at line 924 of file Guid.cs.

925 {
926 if (format.Length == 0)
927 {
928 format = "D";
929 }
930 if (format.Length != 1)
931 {
932 throw new FormatException(SR.Format_InvalidGuidFormatSpecification);
933 }
934 bool flag = true;
935 bool flag2 = false;
936 int num = 0;
937 int num2;
938 switch (format[0])
939 {
940 case 'D':
941 case 'd':
942 num2 = 36;
943 break;
944 case 'N':
945 case 'n':
946 flag = false;
947 num2 = 32;
948 break;
949 case 'B':
950 case 'b':
951 num = 8192123;
952 num2 = 38;
953 break;
954 case 'P':
955 case 'p':
956 num = 2687016;
957 num2 = 38;
958 break;
959 case 'X':
960 case 'x':
961 num = 8192123;
962 flag = false;
963 flag2 = true;
964 num2 = 68;
965 break;
966 default:
967 throw new FormatException(SR.Format_InvalidGuidFormatSpecification);
968 }
969 if (destination.Length < num2)
970 {
971 charsWritten = 0;
972 return false;
973 }
974 fixed (char* ptr = &MemoryMarshal.GetReference(destination))
975 {
976 char* ptr2 = ptr;
977 if (num != 0)
978 {
979 *(ptr2++) = (char)num;
980 }
981 if (flag2)
982 {
983 *(ptr2++) = '0';
984 *(ptr2++) = 'x';
985 ptr2 += HexsToChars(ptr2, _a >> 24, _a >> 16);
986 ptr2 += HexsToChars(ptr2, _a >> 8, _a);
987 *(ptr2++) = ',';
988 *(ptr2++) = '0';
989 *(ptr2++) = 'x';
990 ptr2 += HexsToChars(ptr2, _b >> 8, _b);
991 *(ptr2++) = ',';
992 *(ptr2++) = '0';
993 *(ptr2++) = 'x';
994 ptr2 += HexsToChars(ptr2, _c >> 8, _c);
995 *(ptr2++) = ',';
996 *(ptr2++) = '{';
997 ptr2 += HexsToCharsHexOutput(ptr2, _d, _e);
998 *(ptr2++) = ',';
999 ptr2 += HexsToCharsHexOutput(ptr2, _f, _g);
1000 *(ptr2++) = ',';
1001 ptr2 += HexsToCharsHexOutput(ptr2, _h, _i);
1002 *(ptr2++) = ',';
1003 ptr2 += HexsToCharsHexOutput(ptr2, _j, _k);
1004 *(ptr2++) = '}';
1005 }
1006 else
1007 {
1008 ptr2 += HexsToChars(ptr2, _a >> 24, _a >> 16);
1009 ptr2 += HexsToChars(ptr2, _a >> 8, _a);
1010 if (flag)
1011 {
1012 *(ptr2++) = '-';
1013 }
1014 ptr2 += HexsToChars(ptr2, _b >> 8, _b);
1015 if (flag)
1016 {
1017 *(ptr2++) = '-';
1018 }
1019 ptr2 += HexsToChars(ptr2, _c >> 8, _c);
1020 if (flag)
1021 {
1022 *(ptr2++) = '-';
1023 }
1024 ptr2 += HexsToChars(ptr2, _d, _e);
1025 if (flag)
1026 {
1027 *(ptr2++) = '-';
1028 }
1029 ptr2 += HexsToChars(ptr2, _f, _g);
1030 ptr2 += HexsToChars(ptr2, _h, _i);
1031 ptr2 += HexsToChars(ptr2, _j, _k);
1032 }
1033 if (num != 0)
1034 {
1035 *(ptr2++) = (char)(num >> 16);
1036 }
1037 }
1038 charsWritten = num2;
1039 return true;
1040 }
readonly short _b
Definition Guid.cs:90
static unsafe int HexsToChars(char *guidChars, int a, int b)
Definition Guid.cs:861
readonly byte _f
Definition Guid.cs:98
readonly byte _h
Definition Guid.cs:102
readonly short _c
Definition Guid.cs:92
readonly byte _j
Definition Guid.cs:106
readonly byte _k
Definition Guid.cs:108
readonly byte _d
Definition Guid.cs:94
readonly byte _e
Definition Guid.cs:96
static unsafe int HexsToCharsHexOutput(char *guidChars, int a, int b)
Definition Guid.cs:870
readonly byte _i
Definition Guid.cs:104
readonly int _a
Definition Guid.cs:88
readonly byte _g
Definition Guid.cs:100

References System.Guid._a, System.Guid._b, System.Guid._c, System.Guid._d, System.Guid._e, System.Guid._f, System.Guid._g, System.Guid._h, System.Guid._i, System.Guid._j, System.Guid._k, System.destination, System.format, System.SR.Format_InvalidGuidFormatSpecification, System.Guid.HexsToChars(), and System.Guid.HexsToCharsHexOutput().

Referenced by System.Guid.ToString(), and System.Guid.TryFormat().