@@ -207,16 +207,25 @@ private static INetworkVariableSerializer<T> GetSerializer()
207
207
{
208
208
return new UnmanagedTypeSerializer < T > ( ) ;
209
209
}
210
+ if ( typeof ( Enum ) . IsAssignableFrom ( typeof ( T ) ) )
211
+ {
212
+ return new UnmanagedTypeSerializer < T > ( ) ;
213
+ }
210
214
211
215
if ( typeof ( INetworkSerializable ) . IsAssignableFrom ( typeof ( T ) ) )
212
216
{
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
213
220
var writeMethod = ( NetworkSerializableSerializer < T > . WriteValueDelegate ) Delegate . CreateDelegate ( typeof ( NetworkSerializableSerializer < T > . WriteValueDelegate ) , null , typeof ( T ) . GetMethod ( nameof ( INetworkSerializable . NetworkSerialize ) ) . MakeGenericMethod ( typeof ( BufferSerializerWriter ) ) ) ;
214
221
var readMethod = ( NetworkSerializableSerializer < T > . ReadValueDelegate ) Delegate . CreateDelegate ( typeof ( NetworkSerializableSerializer < T > . ReadValueDelegate ) , null , typeof ( T ) . GetMethod ( nameof ( INetworkSerializable . NetworkSerialize ) ) . MakeGenericMethod ( typeof ( BufferSerializerReader ) ) ) ;
215
222
return new NetworkSerializableSerializer < T > { WriteValue = writeMethod , ReadValue = readMethod } ;
216
223
}
217
224
218
225
if ( typeof ( IUTF8Bytes ) . IsAssignableFrom ( typeof ( T ) ) && typeof ( INativeList < byte > ) . IsAssignableFrom ( typeof ( T ) ) )
219
226
{
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()
220
229
var getLength = ( FixedStringSerializer < T > . GetLengthDelegate ) Delegate . CreateDelegate ( typeof ( FixedStringSerializer < T > . GetLengthDelegate ) , null , typeof ( T ) . GetMethod ( "get_" + nameof ( INativeList < byte > . Length ) ) ) ;
221
230
var setLength = ( FixedStringSerializer < T > . SetLengthDelegate ) Delegate . CreateDelegate ( typeof ( FixedStringSerializer < T > . SetLengthDelegate ) , null , typeof ( T ) . GetMethod ( "set_" + nameof ( INativeList < byte > . Length ) ) ) ;
222
231
var getUnsafePtr = ( FixedStringSerializer < T > . GetUnsafePtrDelegate ) Delegate . CreateDelegate ( typeof ( FixedStringSerializer < T > . GetUnsafePtrDelegate ) , null , typeof ( T ) . GetMethod ( nameof ( IUTF8Bytes . GetUnsafePtr ) ) ) ;
0 commit comments