public TupleSerializer(RuntimeTypeModel model, ConstructorInfo ctor, MemberInfo[] members) { this.ctor = ctor ?? throw new ArgumentNullException(nameof(ctor)); this.members = members ?? throw new ArgumentNullException(nameof(members)); this.tails = new IProtoSerializer[members.Length]; ParameterInfo[] parameters = ctor.GetParameters(); for (int i = 0; i < members.Length; i++) { WireType wireType; Type finalType = parameters[i].ParameterType; Type itemType = null, defaultType = null; MetaType.ResolveListTypes(model, finalType, ref itemType, ref defaultType); Type tmp = itemType == null ? finalType : itemType; bool asReference = false; int typeIndex = model.FindOrAddAuto(tmp, false, true, false); if (typeIndex >= 0) { asReference = model[tmp].AsReferenceDefault; } IProtoSerializer tail = ValueMember.TryGetCoreSerializer(model, DataFormat.Default, tmp, out wireType, asReference, false, false, true), serializer; if (tail == null) { throw new InvalidOperationException("No serializer defined for type: " + tmp.FullName); } tail = new TagDecorator(i + 1, wireType, false, tail); if (itemType == null) { serializer = tail; } else { if (finalType.IsArray) { serializer = new ArrayDecorator(model, tail, i + 1, false, wireType, finalType, false, false); } else { serializer = ListDecorator.Create(model, finalType, defaultType, tail, i + 1, false, wireType, true, false, false); } } tails[i] = serializer; } }
private bool CanUsePackedPrefix(object obj) => ArrayDecorator.CanUsePackedPrefix(packedWireType, Tail.ExpectedType);