private void EnqueueAdditionalTypesToInclude(
            TypeToRegister typeToRegister,
            IReadOnlyCollection <Type> additionalTypesToInclude,
            TypeToIncludeOrigin typeToIncludeOrigin,
            Queue <TypeToRegister> typesToRegisterQueue)
        {
            // This excludes typeToRegister.Type (the dequeued value),
            // so it's not possible to create any more originating types.
            additionalTypesToInclude =
                additionalTypesToInclude
                .Distinct()
                .Where(_ => !VersionlessOpenTypeConsolidatingTypeEqualityComparer.Instance.Equals(_, typeToRegister.Type))
                .ToList();

            foreach (var additionalTypeToInclude in additionalTypesToInclude)
            {
                var additionalTypeToRegister = typeToRegister.CreateSpawnedTypeToRegister(additionalTypeToInclude, typeToIncludeOrigin);

                var additionalTypeToRegisterId = BuildIdIgnoringOrigin(additionalTypeToRegister);

                if (!this.visitedTypesToRegisterIds.Contains(additionalTypeToRegisterId))
                {
                    typesToRegisterQueue.Enqueue(additionalTypeToRegister);
                }
            }
        }
        private RegistrationDetails RegisterType(
            TypeToRegister typeToRegister,
            RegistrationTime registrationTime)
        {
            if (typeToRegister == null)
            {
                throw new ArgumentNullException(nameof(typeToRegister));
            }

            var result = new RegistrationDetails(typeToRegister, this.SerializationConfigurationType);

            this.RegisterType(result, registrationTime);

            return(result);
        }
示例#3
0
        private static string BuildIdIgnoringOrigin(
            TypeToRegister typeToRegister)
        {
            string result;

            if (typeToRegister.Type.ContainsGenericParameters && (!typeToRegister.Type.IsGenericTypeDefinition))
            {
                // this branch is needed because ToRepresentation() below will throw on this kind of type
                result = "OPEN_" + typeToRegister.Type;
            }
            else
            {
                result = typeToRegister.Type.ToRepresentation().RemoveAssemblyVersions().BuildAssemblyQualifiedName();
            }

            var typesToIncludeSuffix = "_" + typeToRegister.RelatedTypesToInclude + "_" + ((int)typeToRegister.MemberTypesToInclude).ToString(CultureInfo.InvariantCulture);

            result = result + typesToIncludeSuffix;

            return(result);
        }
示例#4
0
        private static bool IsTypeThatCanBeRegistered(
            TypeToRegister typeToRegister)
        {
            var type = typeToRegister.Type;

            // open type is only allowed if it is a generic type definition
            if (type.ContainsGenericParameters && (!type.IsGenericTypeDefinition))
            {
                return(false);
            }

            if (CannotBeRegisteredSystemTypes.Contains(type))
            {
                return(false);
            }

            // System types can be registered directly (e.g. needed to register serializer for System.Drawing.Color)
            if (type.IsSystemType())
            {
                if (typeToRegister.IsOriginatingType)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            if (IsRestrictedType(type))
            {
                return(false);
            }

            return(true);
        }