Ejemplo n.º 1
0
        Nullability LoadNullabilityConstraint()
        {
            if (!module.ShouldDecodeNullableAttributes(Owner))
            {
                return(Nullability.Oblivious);
            }

            var metadata = module.metadata;
            var gp       = metadata.GetGenericParameter(handle);

            foreach (var handle in gp.GetCustomAttributes())
            {
                var customAttribute = metadata.GetCustomAttribute(handle);
                if (customAttribute.IsKnownAttribute(metadata, KnownAttribute.Nullable))
                {
                    var attrVal = customAttribute.DecodeValue(module.TypeProvider);
                    if (attrVal.FixedArguments.Length == 1)
                    {
                        if (attrVal.FixedArguments[0].Value is byte b && b <= 2)
                        {
                            return((Nullability)b);
                        }
                    }
                }
            }
            if (Owner is MetadataMethod method)
            {
                return(method.NullableContext);
            }
            else if (Owner is ITypeDefinition td)
            {
                return(td.NullableContext);
            }
            else
            {
                return(Nullability.Oblivious);
            }
        }