コード例 #1
0
            private static IEnumerable <Type> ExtractElementTypes(SerializationContext context, ISerializerGeneratorConfiguration configuration, Type type)
            {
                if (!SerializationTarget.BuiltInSerializerExists(configuration, type, type.GetCollectionTraits(CollectionTraitOptions.None, context.CompatibilityOptions.AllowNonCollectionEnumerableTypes)))
                {
                    yield return(type);

                    // Search dependents recursively if the type is NOT enum.
                    if (!type.GetIsEnum())
                    {
                        foreach (
                            var dependentType in
                            SerializationTarget.Prepare(context, type)
                            .Members.Where(m => m.Member != null).SelectMany(m => ExtractElementTypes(context, configuration, m.Member.GetMemberValueType()))
                            )
                        {
                            yield return(dependentType);
                        }
                    }
                }

                if (type.IsArray)
                {
                    var elementType = type.GetElementType();
                    if (!SerializationTarget.BuiltInSerializerExists(configuration, elementType, elementType.GetCollectionTraits(CollectionTraitOptions.None, allowNonCollectionEnumerableTypes: false)))
                    {
                        foreach (var descendant in ExtractElementTypes(context, configuration, elementType))
                        {
                            yield return(descendant);
                        }

                        yield return(elementType);
                    }

                    yield break;
                }

                if (type.IsGenericType)
                {
                    // Search generic arguments recursively.
                    foreach (var elementType in type.GetGenericArguments().SelectMany(g => ExtractElementTypes(context, configuration, g)))
                    {
                        yield return(elementType);
                    }
                }

                if (configuration.WithNullableSerializers && type.GetIsValueType() && Nullable.GetUnderlyingType(type) == null)
                {
                    // Retrun nullable companion even if they always have built-in serializers.
                    yield return(typeof(Nullable <>).MakeGenericType(type));
                }
            }
コード例 #2
0
            private static IEnumerable <Type> ExtractElementTypes(SerializationContext context, ISerializerGeneratorConfiguration configuration, Type type)
            {
                if (!SerializationTarget.BuiltInSerializerExists(configuration, type, type.GetCollectionTraits()))
                {
                    yield return(type);

                    // Search dependents recursively.
                    foreach (var dependentType in SerializationTarget.Prepare(context, type).Members.SelectMany(m => ExtractElementTypes(context, configuration, m.Member.GetMemberValueType())))
                    {
                        yield return(dependentType);
                    }
                }

                if (type.IsArray)
                {
                    var elementType = type.GetElementType();
                    if (!SerializationTarget.BuiltInSerializerExists(configuration, elementType, elementType.GetCollectionTraits()))
                    {
                        yield return(elementType);
                    }

                    yield break;
                }

                if (type.IsGenericType)
                {
                    // Search generic arguments recursively.
                    foreach (var elementType in type.GetGenericArguments().SelectMany(g => ExtractElementTypes(context, configuration, g)))
                    {
                        yield return(elementType);
                    }
                }
            }
コード例 #3
0
 public static bool BuiltInSerializerExists(ISerializerGeneratorConfiguration configuration, Type type, CollectionTraits traits)
 {
     return(GenericSerializer.IsSupported(type, traits, configuration.PreferReflectionBasedSerializer) || SerializerRepository.InternalDefault.Contains(type));
 }
コード例 #4
0
		public static bool BuiltInSerializerExists( ISerializerGeneratorConfiguration configuration, Type type, CollectionTraits traits )
		{
			return GenericSerializer.IsSupported( type, traits, configuration.PreferReflectionBasedSerializer ) || SerializerRepository.InternalDefault.Contains( type );
		}