private void DeserializeObjectInto(object instance, TypeInfo typeInfo) { List <MemberValue> values = (typeInfo != null && (typeInfo.HasDataContract || typeInfo.BaseHasDataContract)) ? this.valueBank.Borrow() : null; for (Item keyItem = this.itemizer.NextItem(); keyItem.Type != ItemType.ObjectEnd; keyItem = this.itemizer.NextItem()) { Key key = this.itemizer.ValueToken.DecodedKey; MemberInfo memberInfo = (typeInfo != null) ? (typeInfo.CollectionMember ?? typeInfo.TryFindMember(key.Text)) : null; MemberValue value = this.DeserializeValue(this.itemizer.NextItem(), instance, key.Text, memberInfo); if (value.IsValid) { if (values != null) { values.Add(value); } else { value.SetValue(this, instance); } } } if (values != null) { values.Sort(MemberValue.ComparisonFunc); foreach (MemberValue value in values) { value.SetValue(this, instance); } this.valueBank.Return(values); } }
public static object Deserialize(Itemizer itemizer, object instance, Type type) { Deserializer deserializer = new Deserializer(itemizer); Result result = new Result(instance); FieldInfo memberInfo = new FieldInfo(deserializer.types.GetTypeInfo(typeof(Result)), Result.ValueField, type ?? instance?.GetType()); MemberValue value = deserializer.DeserializeValue(itemizer.NextItem(), result, nameof(Result.value), memberInfo); Debug.Assert(itemizer.NextItem().Type == ItemType.End); value.SetValue(deserializer, result); return(result.value); }
private void DeserializeArrayInto(object instance, TypeInfo typeInfo) { MemberInfo memberInfo = typeInfo?.CollectionMember; for (Item item = this.itemizer.NextItem(); item.Type != ItemType.ArrayEnd; item = this.itemizer.NextItem()) { MemberValue value = this.DeserializeValue(item, instance, null, memberInfo); if (value.IsValid) { value.SetValue(this, instance); } } }