Skip to content

Commit fe74a1c

Browse files
committed
添加 Xid 类型的字符串格式化
1 parent c4489b8 commit fe74a1c

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/SeWzc.X11Sharp.SourceGenerator/IncrementalGenerator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ namespace {{namespaceName}};
6969
7070
partial {{keyword}} {{typeDeclaration.Identifier}} : IComparable<{{typeDeclaration.Identifier}}>
7171
{
72+
/// <inheritdoc />
73+
public override string ToString()
74+
{
75+
return $"0x{Id:X}";
76+
}
77+
7278
/// <inheritdoc />
7379
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7480
public int CompareTo({{typeDeclaration.Identifier}} other)

src/SeWzc.X11Sharp/Structs/Long.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Runtime.CompilerServices;
34
using System.Runtime.InteropServices;
45

@@ -9,7 +10,7 @@ namespace SeWzc.X11Sharp.Structs;
910
/// </summary>
1011
/// <param name="Value">内部的 CLong 类型。</param>
1112
[EditorBrowsable(EditorBrowsableState.Advanced)]
12-
public readonly record struct Long(CLong Value) : IComparable<Long>
13+
public readonly record struct Long(CLong Value) : IComparable<Long>, IFormattable
1314
{
1415
/// <summary>
1516
/// 使用 nint 构造 Long。
@@ -34,6 +35,18 @@ public int CompareTo(Long other)
3435
return Value.Value.CompareTo(other.Value.Value);
3536
}
3637

38+
/// <inheritdoc />
39+
public override string ToString()
40+
{
41+
return Value.Value.ToString();
42+
}
43+
44+
/// <inheritdoc />
45+
public string ToString([StringSyntax("NumericFormat")] string? format, IFormatProvider? provider = null)
46+
{
47+
return Value.Value.ToString(format, provider);
48+
}
49+
3750
#region 运算符重载
3851

3952
// 强制转换就不用文档了

src/SeWzc.X11Sharp/Structs/ULong.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Runtime.CompilerServices;
34
using System.Runtime.InteropServices;
45

@@ -9,7 +10,7 @@ namespace SeWzc.X11Sharp.Structs;
910
/// </summary>
1011
/// <param name="Value">内部的 CULong 类型。</param>
1112
[EditorBrowsable(EditorBrowsableState.Advanced)]
12-
public readonly record struct ULong(CULong Value) : IComparable<ULong>
13+
public readonly record struct ULong(CULong Value) : IComparable<ULong>, IFormattable
1314
{
1415
/// <summary>
1516
/// 使用 nuint 构造 ULong。
@@ -34,6 +35,18 @@ public int CompareTo(ULong other)
3435
return Value.Value.CompareTo(other.Value.Value);
3536
}
3637

38+
/// <inheritdoc />
39+
public override string ToString()
40+
{
41+
return Value.Value.ToString();
42+
}
43+
44+
/// <inheritdoc />
45+
public string ToString([StringSyntax("NumericFormat")] string? format, IFormatProvider? provider = null)
46+
{
47+
return Value.Value.ToString(format, provider);
48+
}
49+
3750
#region 运算符重载
3851

3952
// 强制转换就不用文档了

0 commit comments

Comments
 (0)