System.Xml.Serialization.XmlReflectionImporter.CreateNullableMapping C# (CSharp) Method

CreateNullableMapping() private method

private CreateNullableMapping ( TypeMapping baseMapping, Type type ) : NullableMapping
baseMapping TypeMapping
type System.Type
return NullableMapping
        private NullableMapping CreateNullableMapping(TypeMapping baseMapping, Type type)
        {
            TypeDesc typeDesc = baseMapping.TypeDesc.GetNullableTypeDesc(type);
            TypeMapping existingMapping;
            if (!baseMapping.IsAnonymousType)
            {
                existingMapping = (TypeMapping)_nullables[baseMapping.TypeName, baseMapping.Namespace];
            }
            else
            {
                existingMapping = (TypeMapping)_anonymous[type];
            }

            NullableMapping mapping;
            if (existingMapping != null)
            {
                if (existingMapping is NullableMapping)
                {
                    mapping = (NullableMapping)existingMapping;
                    if (mapping.BaseMapping is PrimitiveMapping && baseMapping is PrimitiveMapping)
                        return mapping;
                    else if (mapping.BaseMapping == baseMapping)
                    {
                        return mapping;
                    }
                    else
                    {
                        throw new InvalidOperationException(SR.Format(SR.XmlTypesDuplicate, typeDesc.FullName, existingMapping.TypeDesc.FullName, typeDesc.Name, existingMapping.Namespace));
                    }
                }
                else
                {
                    throw new InvalidOperationException(SR.Format(SR.XmlTypesDuplicate, typeDesc.FullName, existingMapping.TypeDesc.FullName, typeDesc.Name, existingMapping.Namespace));
                }
            }
            mapping = new NullableMapping();
            mapping.BaseMapping = baseMapping;
            mapping.TypeDesc = typeDesc;
            mapping.TypeName = baseMapping.TypeName;
            mapping.Namespace = baseMapping.Namespace;
            mapping.IncludeInSchema = baseMapping.IncludeInSchema;
            if (!baseMapping.IsAnonymousType)
            {
                _nullables.Add(baseMapping.TypeName, baseMapping.Namespace, mapping);
            }
            else
            {
                _anonymous[type] = mapping;
            }

            _typeScope.AddTypeMapping(mapping);
            return mapping;
        }