private static bool TestIfNestedNotSupported(RepeatedSerializerStub repeated)
        {
            if (repeated?.ItemType is null) return false; // fine

            if (!repeated.IsMap) // we allow nesting on dictionaries, just not on arrays/lists etc
            {
                if (repeated.ItemType == repeated.ForType || TryGetRepeatedProvider(repeated.ItemType) is object) return true;
            }
            return false;
        }
        internal static RepeatedSerializerStub TryGetRepeatedProvider(Type type)
        {
            if (type == null || type == typeof(string))
            {
                return(null);
            }

            var known = (RepeatedSerializerStub)s_knownTypes[type];

            if (known == null)
            {
                Type genDef;
                if (type.IsGenericType && Array.IndexOf(NotSupportedFlavors, (genDef = type.GetGenericTypeDefinition())) >= 0)
                {
                    if (genDef == typeof(Span <>) || genDef == typeof(ReadOnlySpan <>))
                    {   // needs special handling because can't use Span<T> as a TSomething in a Foo<TSomething>
                        throw new NotSupportedException("Serialization cannot work with [ReadOnly]Span<T>; [ReadOnly]Memory<T> may be enabled later");
                    }
                    known = NotSupported(s_GeneralNotSupported, type, type.GetGenericArguments()[0]);
                }
                else
                {
                    var rawProvider = GetProviderForType(type);
                    if (rawProvider == null)
                    {
                        if (type.IsArray && type != typeof(byte[]))
                        {
                            // multi-dimensional
                            known = NotSupported(s_GeneralNotSupported, type, type.GetElementType());
                        }
                        else
                        {   // not repeated
                            known = RepeatedSerializerStub.Empty;
                        }
                    }
                    else
                    {
                        // check for nesting
                        known = RepeatedSerializerStub.Create(type, rawProvider);
                        if (TestIfNestedNotSupported(known))
                        {
                            known = NotSupported(s_NestedNotSupported, known.ForType, known.ItemType);
                        }
                    }
                }


                lock (s_knownTypes)
                {
                    s_knownTypes[type] = known;
                }
            }

            return(known.IsEmpty ? null : known);
        }
 private static bool TestIfNestedNotSupported(RepeatedSerializerStub repeated)
 {
     if (repeated?.ItemType == null)
     {
         return(false);   // fine
     }
     if (!repeated.IsMap) // we allow nesting on dictionaries, just not on arrays/lists etc
     {
         if (repeated.ItemType == repeated.ForType || TryGetRepeatedProvider(repeated.ItemType) != null)
         {
             return(true);
         }
     }
     return(false);
 }
 internal static RepeatedSerializerStub NotSupported(MethodInfo kind, Type collectionType, Type itemType)
     => RepeatedSerializerStub.Create(collectionType, kind.MakeGenericMethod(collectionType, itemType));