@@ -12,7 +12,7 @@ public class TypeDescriptor<T> : IDescriptor<T>, ICopyDescriptor<T> where T : IG
12
12
{
13
13
private readonly SetterInfo < T > [ ] setters ;
14
14
private readonly PrinterInfo < T > [ ] printers ;
15
- private readonly Dictionary < string , int > mappings ;
15
+ private readonly Dictionary < string , int > ? mappings ;
16
16
private readonly string sense ;
17
17
private readonly Func < T > create ;
18
18
private readonly bool isStruct ;
@@ -21,7 +21,7 @@ public class TypeDescriptor<T> : IDescriptor<T>, ICopyDescriptor<T> where T : IG
21
21
public TypeDescriptor ( )
22
22
{
23
23
var type = typeof ( T ) ;
24
- create = CreateInstanceExpression < T > ( type ) . Compile ( ) ;
24
+ create = CreateInstanceExpression < T > ( ) . Compile ( ) ;
25
25
26
26
var senseAttribute = type . GetCustomAttribute < SenseAttribute > ( ) ;
27
27
if ( senseAttribute == null )
@@ -33,7 +33,6 @@ public TypeDescriptor()
33
33
var members = GetPropertiesAndFields ( type )
34
34
. Select ( member => ( member , attribute : member . GetCustomAttribute < GamePropertyAttribute > ( ) ) )
35
35
. Where ( x => x . attribute != null )
36
- . Where ( x => ! x . attribute . IgnoreField )
37
36
. ToArray ( ) ;
38
37
var createSetter = typeof ( TypeDescriptorHelper )
39
38
. GetMethod ( nameof ( TypeDescriptorHelper . CreateSetter ) , BindingFlags . Static | BindingFlags . NonPublic ) ;
@@ -91,14 +90,13 @@ public T Create(ReadOnlySpan<char> raw)
91
90
if ( ! int . TryParse ( key . ToString ( ) , out var index ) )
92
91
#endif
93
92
{
94
- var keyString = key . ToString ( ) ;
95
- if ( ! mappings . TryGetValue ( keyString , out var mapped ) )
93
+ if ( mappings == null || ! mappings . TryGetValue ( key . ToString ( ) , out var mapped ) )
96
94
{
97
95
instance . WithoutLoaded . Add ( $ "{ key . ToString ( ) } { sense } { value . ToString ( ) } ") ;
98
96
continue ;
99
97
}
100
98
if ( ! TrySet ( instance , mapped , value ) )
101
- instance . WithoutLoaded . Add ( $ "{ keyString } { sense } { value . ToString ( ) } ") ;
99
+ instance . WithoutLoaded . Add ( $ "{ key . ToString ( ) } { sense } { value . ToString ( ) } ") ;
102
100
continue ;
103
101
}
104
102
if ( ! TrySet ( instance , baseIndex + index , value ) )
@@ -187,19 +185,19 @@ private PrinterInfo<T>[] InitPrinters(IEnumerable<(MemberInfo member, GameProper
187
185
. ToArray ( ) ;
188
186
}
189
187
190
- private static Expression < Func < TB > > CreateInstanceExpression < TB > ( Type type )
188
+ private static Expression < Func < TB > > CreateInstanceExpression < TB > ( )
191
189
{
192
- var ctor = Expression . New ( type ) ;
190
+ var ctor = Expression . New ( typeof ( TB ) ) ;
193
191
var memberInit = Expression . MemberInit ( ctor ) ;
194
192
195
193
return Expression . Lambda < Func < TB > > ( memberInit ) ;
196
194
}
197
195
198
- private static ( SetterInfo < T > [ ] , int baseIndex , Dictionary < string , int > mappings ) InitSetters ( Type type , IEnumerable < ( MemberInfo member , GamePropertyAttribute attribute ) > members )
196
+ private static ( SetterInfo < T > [ ] , int baseIndex , Dictionary < string , int > ? mappings ) InitSetters ( Type type , IEnumerable < ( MemberInfo member , GamePropertyAttribute attribute ) > members )
199
197
{
200
198
var keys = new HashSet < string > ( ) ;
201
199
var maxKeyValue = 0 ;
202
- Dictionary < string , int > mappings = null ;
200
+ Dictionary < string , int > ? mappings = null ;
203
201
foreach ( var ( member , attribute ) in members )
204
202
{
205
203
if ( int . TryParse ( attribute . Key , out var key ) )
@@ -212,9 +210,9 @@ private static (SetterInfo<T>[], int baseIndex, Dictionary<string, int> mappings
212
210
continue ;
213
211
}
214
212
215
- mappings ??= new Dictionary < string , int > ( ) ;
216
213
if ( attribute . KeyOverride == - 1 )
217
214
throw new InvalidOperationException ( $ "Key override for member '{ attribute . Key } ' in { type . Name } is not set") ;
215
+ mappings ??= new Dictionary < string , int > ( ) ;
218
216
mappings . Add ( attribute . Key , attribute . KeyOverride ) ;
219
217
}
220
218
@@ -239,7 +237,7 @@ private static IEnumerable<MemberInfo> GetPropertiesAndFields(Type type)
239
237
var current = type ;
240
238
while ( current != null && current != typeof ( object ) )
241
239
{
242
- foreach ( var field in current . GetFields ( BindingFlags . Instance | BindingFlags . NonPublic ) )
240
+ foreach ( var field in current . GetFields ( BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . DeclaredOnly ) )
243
241
yield return field ;
244
242
current = current . BaseType ;
245
243
}
@@ -519,12 +517,12 @@ private static Expression<Setter<TInstance>> CreateEnumSetter<TProp, TInstance>(
519
517
) ;
520
518
}
521
519
522
- private static MethodInfo GetParserMethod < TProp > ( out Expression instanceExpression )
520
+ private static MethodInfo GetParserMethod < TProp > ( out Expression ? instanceExpression )
523
521
{
524
522
return GetParserMethod ( typeof ( TProp ) , out instanceExpression ) ;
525
523
}
526
524
527
- private static MethodInfo GetParserMethod ( Type propType , out Expression serializerExp )
525
+ private static MethodInfo GetParserMethod ( Type propType , out Expression ? serializerExp )
528
526
{
529
527
if ( typeof ( IGameObject ) . IsAssignableFrom ( propType ) )
530
528
{
0 commit comments