@@ -11,16 +11,10 @@ public struct BaseHandle : IEquatable<BaseHandle>, IBaseHandle
1111 public readonly uint Unpack ( ) => Index ;
1212
1313
14- public void Invalidate ( ) => Index = ( uint ) Constants . INVALID_EHANDLE_INDEX ;
15- public BaseHandle ( ) => Invalidate ( ) ;
14+ public BaseHandle ( ) => Index = ( uint ) Constants . INVALID_EHANDLE_INDEX ;
1615 public BaseHandle ( uint value ) => Index = value ;
1716 public BaseHandle ( in BaseHandle handle ) => Index = handle . Index ;
18- public BaseHandle ( int entry , int serial ) => Init ( entry , serial ) ;
19-
20- public void Init ( in BaseHandle otherHandle ) => Index = otherHandle . Index ;
21- public void Init ( uint entindex ) => Index = entindex ;
22- public void Init ( ulong entindex ) => Index = ( uint ) entindex ;
23- public void Init ( int entry , int serial ) => Index = ( uint ) ( entry | ( serial << Constants . NUM_ENT_ENTRY_BITS ) ) ;
17+ public BaseHandle ( int entry , int serial ) => Index = ( uint ) ( entry | ( serial << Constants . NUM_ENT_ENTRY_BITS ) ) ;
2418
2519 public readonly int GetEntryIndex ( ) => ( int ) ( Index & Constants . ENT_ENTRY_MASK ) ;
2620 public readonly int GetSerialNumber ( ) => ( int ) ( Index >> Constants . NUM_ENT_ENTRY_BITS ) ;
@@ -37,14 +31,6 @@ public override readonly bool Equals(object? obj) {
3731 }
3832 public override readonly int GetHashCode ( ) => ( int ) Index ;
3933 public readonly bool IsValid ( ) => Index != Constants . INVALID_EHANDLE_INDEX ;
40-
41- public BaseHandle Set ( IHandleEntity ? entity ) {
42- if ( entity != null )
43- this . Index = entity . GetRefEHandle ( ) . Index ;
44- else
45- Index = Constants . INVALID_EHANDLE_INDEX ;
46- return this ;
47- }
4834}
4935
5036
@@ -60,16 +46,10 @@ public struct Handle<T> : IEquatable<Handle<T>>, IEquatable<BaseHandle>, IBaseHa
6046 public readonly bool Equals ( BaseHandle otherHandle ) => Index == otherHandle . Index ;
6147 public uint Index ;
6248
63- public void Invalidate ( ) => Index = ( uint ) Constants . INVALID_EHANDLE_INDEX ;
64- public Handle ( ) => Invalidate ( ) ;
49+ public Handle ( ) => Index = ( uint ) Constants . INVALID_EHANDLE_INDEX ;
6550 public Handle ( uint value ) => Index = value ;
6651 public Handle ( in BaseHandle handle ) => Index = handle . Index ;
67- public Handle ( int entry , int serial ) => Init ( entry , serial ) ;
68-
69- public void Init ( in BaseHandle otherHandle ) => Index = otherHandle . Index ;
70- public void Init ( uint entindex ) => Index = entindex ;
71- public void Init ( ulong entindex ) => Index = ( uint ) entindex ;
72- public void Init ( int entry , int serial ) => Index = ( uint ) ( entry | ( serial << Constants . NUM_ENT_ENTRY_BITS ) ) ;
52+ public Handle ( int entry , int serial ) => Index = ( uint ) ( entry | ( serial << Constants . NUM_ENT_ENTRY_BITS ) ) ;
7353
7454 public readonly int GetEntryIndex ( ) => ( int ) ( Index & Constants . ENT_ENTRY_MASK ) ;
7555 public readonly int GetSerialNumber ( ) => ( int ) ( Index >> Constants . NUM_ENT_ENTRY_BITS ) ;
@@ -103,12 +83,37 @@ public override readonly bool Equals(object? obj) {
10383
10484 public override readonly int GetHashCode ( ) => ( int ) Index ;
10585 public readonly bool IsValid ( ) => Index != Constants . INVALID_EHANDLE_INDEX ;
86+ }
87+
88+ public static class BaseHandleExts
89+ {
90+ public static void Invalidate ( ref this BaseHandle handle ) => handle . Index = ( uint ) Constants . INVALID_EHANDLE_INDEX ;
91+
92+ public static void Init ( ref this BaseHandle handle , in BaseHandle otherHandle ) => handle . Index = otherHandle . Index ;
93+ public static void Init ( ref this BaseHandle handle , uint entindex ) => handle . Index = entindex ;
94+ public static void Init ( ref this BaseHandle handle , ulong entindex ) => handle . Index = ( uint ) entindex ;
95+ public static void Init ( ref this BaseHandle handle , int entry , int serial ) => handle . Index = ( uint ) ( entry | ( serial << Constants . NUM_ENT_ENTRY_BITS ) ) ;
96+
97+ public static BaseHandle Set ( ref this BaseHandle handle , IHandleEntity ? entity ) {
98+ if ( entity != null )
99+ handle . Index = entity . GetRefEHandle ( ) . Index ;
100+ else
101+ handle . Index = Constants . INVALID_EHANDLE_INDEX ;
102+ return handle ;
103+ }
104+
105+ public static void Invalidate < T > ( ref this Handle < T > handle ) => handle . Index = ( uint ) Constants . INVALID_EHANDLE_INDEX ;
106+
107+ public static void Init < T > ( ref this Handle < T > handle , in BaseHandle otherHandle ) => handle . Index = otherHandle . Index ;
108+ public static void Init < T > ( ref this Handle < T > handle , uint entindex ) => handle . Index = entindex ;
109+ public static void Init < T > ( ref this Handle < T > handle , ulong entindex ) => handle . Index = ( uint ) entindex ;
110+ public static void Init < T > ( ref this Handle < T > handle , int entry , int serial ) => handle . Index = ( uint ) ( entry | ( serial << Constants . NUM_ENT_ENTRY_BITS ) ) ;
106111
107- public Handle < T > Set ( IHandleEntity ? entity ) {
112+ public static Handle < T > Set < T > ( ref this Handle < T > handle , IHandleEntity ? entity ) {
108113 if ( entity != null )
109- this . Index = entity . GetRefEHandle ( ) . Index ;
114+ handle . Index = entity . GetRefEHandle ( ) . Index ;
110115 else
111- Index = Constants . INVALID_EHANDLE_INDEX ;
112- return this ;
116+ handle . Index = Constants . INVALID_EHANDLE_INDEX ;
117+ return handle ;
113118 }
114119}
0 commit comments