public static void AvoidLinkedListStackOverflow() { var value = PersistentList.Of(Enumerable.Range(0, 3000)); var typeConverters = new[] { PersistentListTypeConverter.Instance }; var clone = BinarySerialisationCloner.Clone(value, typeConverters, typeConverters, ReferenceReuseOptions.SupportReferenceReUseInMostlyTreeLikeStructure); Assert.Equal(value.ToArray(), clone.ToArray()); }
public static void DoNotTryToGenerateMemberSettersForConvertedTypes() => AssertCanGenerateCorrectMemberSetter( new SomethingWithImmutableListProperty { Roles = PersistentList.Of(new[] { "abc", "def" }) }, new[] { ImmutableListTypeConverter.Instance }, // Use ImmutableListTypeConverter instead of PersistentListTypeConverter because the latter doesn't implement IFastSerialisationTypeConverter expectedNumberOfMemberSettersGenerated: 2, expectedNumberOfMemberSettersThatCanNotBeGenerated: 0 );
private static object ConvertIfRequired <T>(object value, Type targetTypeIfDeserialising) { if (value != null) { // If targetTypeIfDeserialising is null then this is a ConvertIfRequired during serialisation if (targetTypeIfDeserialising == null) { return(((value is PersistentList <T> list)) ? list.ToArray() : value); } if (targetTypeIfDeserialising == typeof(PersistentList <T>)) { return(((value is IEnumerable <T> enumerable)) ? PersistentList.Of(enumerable) : value); } } return(value); }
protected override IEnumerable <T> GetList <T>(T[] valuesIfAny) => (valuesIfAny == null) ? null : PersistentList.Of(valuesIfAny);