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}
0 commit comments