protected override void InitializeCreatorArgumentCaches(ref ReadStack state, BinarySerializerOptions options) { // 设置属性 BinaryClassInfo classInfo = state.Current.BinaryClassInfo; if (state.Current.PropertyValueCache == null) { for (int i = 0; i < classInfo.PropertyCacheArray.Length; i++) { classInfo.PropertyCacheArray[i].ShouldDeserialize = true; } state.Current.PropertyValueCache = new Dictionary <string, object>(); } }
protected override void InitializeConstructorArgumentCaches(ref ReadStack state, BinarySerializerOptions options) { BinaryClassInfo classInfo = state.Current.BinaryClassInfo; if (classInfo.CreateObjectWithArgs == null) { classInfo.CreateObjectWithArgs = options.MemberAccessorStrategy.CreateParameterizedConstructor <T, TArg0, TArg1, TArg2, TArg3>(ConstructorInfo !); } var arguments = new Arguments <TArg0, TArg1, TArg2, TArg3>(); foreach (BinaryParameterInfo parameterInfo in classInfo.ParameterCache !.Values) { if (parameterInfo.ShouldDeserialize) { int position = parameterInfo.Position; switch (position) { case 0: arguments.Arg0 = ((BinaryParameterInfo <TArg0>)parameterInfo).TypedDefaultValue !; break; case 1: arguments.Arg1 = ((BinaryParameterInfo <TArg1>)parameterInfo).TypedDefaultValue !; break; case 2: arguments.Arg2 = ((BinaryParameterInfo <TArg2>)parameterInfo).TypedDefaultValue !; break; case 3: arguments.Arg3 = ((BinaryParameterInfo <TArg3>)parameterInfo).TypedDefaultValue !; break; default: Debug.Fail("More than 4 params: we should be in override for LargeObjectWithParameterizedConstructorConverter."); throw new InvalidOperationException(); } } } state.Current.CtorArgumentState !.Arguments = arguments; }