@@ -12,7 +12,7 @@ public class TypeDescriptor<T> : IDescriptor<T>, ICopyDescriptor<T> where T : IG
1212 {
1313 private readonly SetterInfo < T > [ ] setters ;
1414 private readonly PrinterInfo < T > [ ] printers ;
15- private readonly Dictionary < string , int > mappings ;
15+ private readonly Dictionary < string , int > ? mappings ;
1616 private readonly string sense ;
1717 private readonly Func < T > create ;
1818 private readonly bool isStruct ;
@@ -21,7 +21,7 @@ public class TypeDescriptor<T> : IDescriptor<T>, ICopyDescriptor<T> where T : IG
2121 public TypeDescriptor ( )
2222 {
2323 var type = typeof ( T ) ;
24- create = CreateInstanceExpression < T > ( type ) . Compile ( ) ;
24+ create = CreateInstanceExpression < T > ( ) . Compile ( ) ;
2525
2626 var senseAttribute = type . GetCustomAttribute < SenseAttribute > ( ) ;
2727 if ( senseAttribute == null )
@@ -33,7 +33,6 @@ public TypeDescriptor()
3333 var members = GetPropertiesAndFields ( type )
3434 . Select ( member => ( member , attribute : member . GetCustomAttribute < GamePropertyAttribute > ( ) ) )
3535 . Where ( x => x . attribute != null )
36- . Where ( x => ! x . attribute . IgnoreField )
3736 . ToArray ( ) ;
3837 var createSetter = typeof ( TypeDescriptorHelper )
3938 . GetMethod ( nameof ( TypeDescriptorHelper . CreateSetter ) , BindingFlags . Static | BindingFlags . NonPublic ) ;
@@ -91,14 +90,13 @@ public T Create(ReadOnlySpan<char> raw)
9190 if ( ! int . TryParse ( key . ToString ( ) , out var index ) )
9291#endif
9392 {
94- var keyString = key . ToString ( ) ;
95- if ( ! mappings . TryGetValue ( keyString , out var mapped ) )
93+ if ( mappings == null || ! mappings . TryGetValue ( key . ToString ( ) , out var mapped ) )
9694 {
9795 instance . WithoutLoaded . Add ( $ "{ key . ToString ( ) } { sense } { value . ToString ( ) } ") ;
9896 continue ;
9997 }
10098 if ( ! TrySet ( instance , mapped , value ) )
101- instance . WithoutLoaded . Add ( $ "{ keyString } { sense } { value . ToString ( ) } ") ;
99+ instance . WithoutLoaded . Add ( $ "{ key . ToString ( ) } { sense } { value . ToString ( ) } ") ;
102100 continue ;
103101 }
104102 if ( ! TrySet ( instance , baseIndex + index , value ) )
@@ -187,19 +185,19 @@ private PrinterInfo<T>[] InitPrinters(IEnumerable<(MemberInfo member, GameProper
187185 . ToArray ( ) ;
188186 }
189187
190- private static Expression < Func < TB > > CreateInstanceExpression < TB > ( Type type )
188+ private static Expression < Func < TB > > CreateInstanceExpression < TB > ( )
191189 {
192- var ctor = Expression . New ( type ) ;
190+ var ctor = Expression . New ( typeof ( TB ) ) ;
193191 var memberInit = Expression . MemberInit ( ctor ) ;
194192
195193 return Expression . Lambda < Func < TB > > ( memberInit ) ;
196194 }
197195
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 )
199197 {
200198 var keys = new HashSet < string > ( ) ;
201199 var maxKeyValue = 0 ;
202- Dictionary < string , int > mappings = null ;
200+ Dictionary < string , int > ? mappings = null ;
203201 foreach ( var ( member , attribute ) in members )
204202 {
205203 if ( int . TryParse ( attribute . Key , out var key ) )
@@ -212,9 +210,9 @@ private static (SetterInfo<T>[], int baseIndex, Dictionary<string, int> mappings
212210 continue ;
213211 }
214212
215- mappings ??= new Dictionary < string , int > ( ) ;
216213 if ( attribute . KeyOverride == - 1 )
217214 throw new InvalidOperationException ( $ "Key override for member '{ attribute . Key } ' in { type . Name } is not set") ;
215+ mappings ??= new Dictionary < string , int > ( ) ;
218216 mappings . Add ( attribute . Key , attribute . KeyOverride ) ;
219217 }
220218
@@ -239,7 +237,7 @@ private static IEnumerable<MemberInfo> GetPropertiesAndFields(Type type)
239237 var current = type ;
240238 while ( current != null && current != typeof ( object ) )
241239 {
242- foreach ( var field in current . GetFields ( BindingFlags . Instance | BindingFlags . NonPublic ) )
240+ foreach ( var field in current . GetFields ( BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . DeclaredOnly ) )
243241 yield return field ;
244242 current = current . BaseType ;
245243 }
@@ -519,12 +517,12 @@ private static Expression<Setter<TInstance>> CreateEnumSetter<TProp, TInstance>(
519517 ) ;
520518 }
521519
522- private static MethodInfo GetParserMethod < TProp > ( out Expression instanceExpression )
520+ private static MethodInfo GetParserMethod < TProp > ( out Expression ? instanceExpression )
523521 {
524522 return GetParserMethod ( typeof ( TProp ) , out instanceExpression ) ;
525523 }
526524
527- private static MethodInfo GetParserMethod ( Type propType , out Expression serializerExp )
525+ private static MethodInfo GetParserMethod ( Type propType , out Expression ? serializerExp )
528526 {
529527 if ( typeof ( IGameObject ) . IsAssignableFrom ( propType ) )
530528 {
0 commit comments