@@ -207,16 +207,25 @@ private static INetworkVariableSerializer<T> GetSerializer()
207207 {
208208 return new UnmanagedTypeSerializer < T > ( ) ;
209209 }
210+ if ( typeof ( Enum ) . IsAssignableFrom ( typeof ( T ) ) )
211+ {
212+ return new UnmanagedTypeSerializer < T > ( ) ;
213+ }
210214
211215 if ( typeof ( INetworkSerializable ) . IsAssignableFrom ( typeof ( T ) ) )
212216 {
217+ // Obtains "Open Instance Delegates" for the type's NetworkSerialize() methods -
218+ // one for an instance of the generic method taking BufferSerializerWriter as T,
219+ // one for an instance of the generic method taking BufferSerializerReader as T
213220 var writeMethod = ( NetworkSerializableSerializer < T > . WriteValueDelegate ) Delegate . CreateDelegate ( typeof ( NetworkSerializableSerializer < T > . WriteValueDelegate ) , null , typeof ( T ) . GetMethod ( nameof ( INetworkSerializable . NetworkSerialize ) ) . MakeGenericMethod ( typeof ( BufferSerializerWriter ) ) ) ;
214221 var readMethod = ( NetworkSerializableSerializer < T > . ReadValueDelegate ) Delegate . CreateDelegate ( typeof ( NetworkSerializableSerializer < T > . ReadValueDelegate ) , null , typeof ( T ) . GetMethod ( nameof ( INetworkSerializable . NetworkSerialize ) ) . MakeGenericMethod ( typeof ( BufferSerializerReader ) ) ) ;
215222 return new NetworkSerializableSerializer < T > { WriteValue = writeMethod , ReadValue = readMethod } ;
216223 }
217224
218225 if ( typeof ( IUTF8Bytes ) . IsAssignableFrom ( typeof ( T ) ) && typeof ( INativeList < byte > ) . IsAssignableFrom ( typeof ( T ) ) )
219226 {
227+ // Get "OpenInstanceDelegates" for the Length property (get and set, which are prefixed
228+ // with "get_" and "set_" under the hood and emitted as methods) and GetUnsafePtr()
220229 var getLength = ( FixedStringSerializer < T > . GetLengthDelegate ) Delegate . CreateDelegate ( typeof ( FixedStringSerializer < T > . GetLengthDelegate ) , null , typeof ( T ) . GetMethod ( "get_" + nameof ( INativeList < byte > . Length ) ) ) ;
221230 var setLength = ( FixedStringSerializer < T > . SetLengthDelegate ) Delegate . CreateDelegate ( typeof ( FixedStringSerializer < T > . SetLengthDelegate ) , null , typeof ( T ) . GetMethod ( "set_" + nameof ( INativeList < byte > . Length ) ) ) ;
222231 var getUnsafePtr = ( FixedStringSerializer < T > . GetUnsafePtrDelegate ) Delegate . CreateDelegate ( typeof ( FixedStringSerializer < T > . GetUnsafePtrDelegate ) , null , typeof ( T ) . GetMethod ( nameof ( IUTF8Bytes . GetUnsafePtr ) ) ) ;
0 commit comments