Skip to content

Commit 8ce66c8

Browse files
committed
优化一些调试输出
1 parent 19174f6 commit 8ce66c8

7 files changed

Lines changed: 185 additions & 14 deletions

File tree

src/dotnetCampus.OpenXMLUnitConverter/EmuPoint.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public EmuPoint(Emu x, Emu y)
3131
/// <inheritdoc />
3232
public bool Equals(EmuPoint other)
3333
{
34-
return X.Equals(other.X) && Y.Equals(other.Y);
34+
return X.Equals(other.X);
3535
}
3636

3737
/// <inheritdoc />
@@ -43,10 +43,26 @@ public override bool Equals(object? obj)
4343
/// <inheritdoc />
4444
public override int GetHashCode()
4545
{
46-
unchecked
47-
{
48-
return (X.GetHashCode() * 397) ^ Y.GetHashCode();
49-
}
46+
return X.GetHashCode();
5047
}
48+
49+
/// <summary>
50+
/// 判断相等
51+
/// </summary>
52+
public static bool operator ==(in EmuPoint left, in EmuPoint right)
53+
{
54+
return left.Equals(right);
55+
}
56+
57+
/// <summary>
58+
/// 判断不相等
59+
/// </summary>
60+
public static bool operator !=(in EmuPoint left, in EmuPoint right)
61+
{
62+
return !left.Equals(right);
63+
}
64+
65+
/// <inheritdoc />
66+
public override string ToString() => $"X={X} ;Y={Y}";
5167
}
5268
}

src/dotnetCampus.OpenXMLUnitConverter/EmuRectangle.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,25 @@ public override int GetHashCode()
6868
return hashCode;
6969
}
7070
}
71+
72+
/// <summary>
73+
/// 判断相等
74+
/// </summary>
75+
public static bool operator ==(in EmuRectangle left,in EmuRectangle right)
76+
{
77+
return left.Equals(right);
78+
}
79+
80+
/// <summary>
81+
/// 判断不相等
82+
/// </summary>
83+
public static bool operator !=(in EmuRectangle left, in EmuRectangle right)
84+
{
85+
return !left.Equals(right);
86+
}
87+
88+
/// <inheritdoc />
89+
public override string ToString() =>
90+
$"{LeftTop} ;{Size}";
7191
}
7292
}

src/dotnetCampus.OpenXMLUnitConverter/EmuSize.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace dotnetCampus.OpenXmlUnitConverter
55
/// <summary>
66
/// 采用 <see cref="Emu"/> 表示的尺寸
77
/// </summary>
8-
public readonly struct EmuSize:IEquatable<EmuSize>
8+
public readonly struct EmuSize : IEquatable<EmuSize>
99
{
1010
/// <summary>
1111
/// 创建使用 EMU 单位表示的 Size 尺寸
@@ -48,5 +48,24 @@ public override int GetHashCode()
4848
return (Width.GetHashCode() * 397) ^ Height.GetHashCode();
4949
}
5050
}
51+
52+
/// <summary>
53+
/// 判断相等
54+
/// </summary>
55+
public static bool operator ==(in EmuSize left, in EmuSize right)
56+
{
57+
return left.Equals(right);
58+
}
59+
60+
/// <summary>
61+
/// 判断不相等
62+
/// </summary>
63+
public static bool operator !=(in EmuSize left, in EmuSize right)
64+
{
65+
return !left.Equals(right);
66+
}
67+
68+
/// <inheritdoc />
69+
public override string ToString() => $"W={Width} ;H={Height}";
5170
}
5271
}

src/dotnetCampus.OpenXMLUnitConverter/MillisecondTime.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,8 @@ public TimeSpan ToTimeSpan() => IsIndefinite
8989
: TimeSpan.FromMilliseconds(Milliseconds);
9090

9191
private const int TicksPerMillisecond = 10000;
92+
93+
/// <inheritdoc />
94+
public override string ToString() => $"Millisecond:{Milliseconds}";
9295
}
9396
}

src/dotnetCampus.OpenXmlUnitConverter/Emu.cs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
namespace dotnetCampus.OpenXmlUnitConverter
1+
using System;
2+
3+
namespace dotnetCampus.OpenXmlUnitConverter
24
{
35
/// <summary>
46
/// 英制公制单位(English Metric Unit)。用于对接厘米(<see cref="Cm"/>)和英寸(<see cref="Inch"/>)的虚拟单位。
57
/// <para>其特殊的数值设计,便于让你在转换百位以内的英寸和毫米、像素长度时,不会产生小数。</para>
68
/// <para>1 <see cref="Inch"/> = 914400 <see cref="Emu"/></para>
79
/// </summary>
8-
public readonly struct Emu
10+
public readonly struct Emu : IEquatable<Emu>
911
{
1012
/// <summary>
1113
/// 创建 <see cref="Emu"/> 单位。
@@ -24,6 +26,49 @@ public Emu(double value)
2426
/// <summary>
2527
/// 表示已初始化为零的 <see cref="Emu"/> 长度。
2628
/// </summary>
27-
public static readonly Emu Zero = new Emu(0);
29+
public static Emu Zero => new Emu(0);
30+
31+
/// <inheritdoc />
32+
public override string ToString() => $"EMU: {Value:0.00}";
33+
34+
/// <inheritdoc />
35+
public bool Equals(Emu other)
36+
{
37+
return Value.Equals(other.Value);
38+
}
39+
40+
/// <inheritdoc />
41+
public override bool Equals(object? obj)
42+
{
43+
return obj is Emu other && Equals(other);
44+
}
45+
46+
/// <inheritdoc />
47+
public override int GetHashCode()
48+
{
49+
return Value.GetHashCode();
50+
}
51+
52+
/// <summary>
53+
/// 判断相等
54+
/// </summary>
55+
/// <param name="left"></param>
56+
/// <param name="right"></param>
57+
/// <returns></returns>
58+
public static bool operator ==(Emu left, Emu right)
59+
{
60+
return left.Equals(right);
61+
}
62+
63+
/// <summary>
64+
/// 判断不相等
65+
/// </summary>
66+
/// <param name="left"></param>
67+
/// <param name="right"></param>
68+
/// <returns></returns>
69+
public static bool operator !=(Emu left, Emu right)
70+
{
71+
return !left.Equals(right);
72+
}
2873
}
2974
}

src/dotnetCampus.OpenXmlUnitConverter/Pixel.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
namespace dotnetCampus.OpenXmlUnitConverter
1+
using System;
2+
3+
namespace dotnetCampus.OpenXmlUnitConverter
24
{
35
/// <summary>
46
/// 像素
57
/// </summary>
6-
public readonly struct Pixel
8+
public readonly struct Pixel : IEquatable<Pixel>
79
{
810
/// <summary>
911
/// 像素
@@ -22,6 +24,27 @@ public Pixel(double value)
2224
/// <summary>
2325
/// 表示值是 0 的像素
2426
/// </summary>
25-
public static readonly Pixel ZeroPixel = new Pixel(0);
27+
public static Pixel ZeroPixel => new Pixel(0);
28+
29+
/// <inheritdoc />
30+
public override string ToString() => $"Pixel:{Value:0.00}";
31+
32+
/// <inheritdoc />
33+
public bool Equals(Pixel other)
34+
{
35+
return Value.Equals(other.Value);
36+
}
37+
38+
/// <inheritdoc />
39+
public override bool Equals(object? obj)
40+
{
41+
return obj is Pixel other && Equals(other);
42+
}
43+
44+
/// <inheritdoc />
45+
public override int GetHashCode()
46+
{
47+
return Value.GetHashCode();
48+
}
2649
}
2750
}

src/dotnetCampus.OpenXmlUnitConverter/Pound.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
namespace dotnetCampus.OpenXmlUnitConverter
1+
using System;
2+
3+
namespace dotnetCampus.OpenXmlUnitConverter
24
{
35
/// <summary>
46
/// 磅
57
/// </summary>
6-
public readonly struct Pound
8+
public readonly struct Pound : IEquatable<Pound>
79
{
810
/// <summary>
911
/// 磅
@@ -18,5 +20,48 @@ public Pound(double value)
1820
/// 磅
1921
/// </summary>
2022
public double Value { get; }
23+
24+
/// <inheritdoc />
25+
public override string ToString() => $"Pound:{Value:0.00}";
26+
27+
/// <inheritdoc />
28+
public bool Equals(Pound other)
29+
{
30+
return Value.Equals(other.Value);
31+
}
32+
33+
/// <inheritdoc />
34+
public override bool Equals(object? obj)
35+
{
36+
return obj is Pound other && Equals(other);
37+
}
38+
39+
/// <inheritdoc />
40+
public override int GetHashCode()
41+
{
42+
return Value.GetHashCode();
43+
}
44+
45+
/// <summary>
46+
/// 判断相等
47+
/// </summary>
48+
/// <param name="left"></param>
49+
/// <param name="right"></param>
50+
/// <returns></returns>
51+
public static bool operator ==(Pound left, Pound right)
52+
{
53+
return left.Equals(right);
54+
}
55+
56+
/// <summary>
57+
/// 判断不相等
58+
/// </summary>
59+
/// <param name="left"></param>
60+
/// <param name="right"></param>
61+
/// <returns></returns>
62+
public static bool operator !=(Pound left, Pound right)
63+
{
64+
return !left.Equals(right);
65+
}
2166
}
2267
}

0 commit comments

Comments
 (0)