Ejemplo n.º 1
0
        /// <summary>
        /// If the type reference has an associated NullableAttribute, this method
        /// returns the type transformed to have IsNullable set to true or false
        /// (but not null) for each reference type in the type.
        /// </summary>
        internal static TypeWithAnnotations TransformType(
            TypeWithAnnotations metadataType,
            EntityHandle targetSymbolToken,
            PEModuleSymbol containingModule,
            Symbol accessSymbol,
            Symbol nullableContext)
        {
            Debug.Assert(metadataType.HasType);
            Debug.Assert(accessSymbol.IsDefinition);
            Debug.Assert((object)accessSymbol.ContainingModule == containingModule);
#if DEBUG
            // Ensure we could check accessibility at this point if we had to in ShouldDecodeNullableAttributes().
            // That is, ensure the accessibility of the symbol (and containing symbols) is available.
            _ = AccessCheck.IsEffectivelyPublicOrInternal(accessSymbol, out _);
#endif

            byte defaultTransformFlag;
            ImmutableArray <byte> nullableTransformFlags;
            if (!containingModule.Module.HasNullableAttribute(targetSymbolToken, out defaultTransformFlag, out nullableTransformFlags))
            {
                byte?value = nullableContext.GetNullableContextValue();
                if (value == null)
                {
                    return(metadataType);
                }
                defaultTransformFlag = value.GetValueOrDefault();
            }

            if (!containingModule.ShouldDecodeNullableAttributes(accessSymbol))
            {
                return(metadataType);
            }

            return(TransformType(metadataType, defaultTransformFlag, nullableTransformFlags));
        }