Skip to content

Thanks and a quick observation #1

@fuocor

Description

@fuocor

This little class has come to the rescue for the code generated JSON serialization I am performing.

For generics it performs a little differently.
The Modes array kicks in with values from the outer most argument to the innermost.
If you want to know if IEnumerable<string>? is nullable then the following does the trick

        public static bool HasNullableAttribute(this PropertyInfo pi)
        {
            var v = pi.GetCustomAttributes(false)
                         .OfType<System.Runtime.CompilerServices.NullableAttribute>()
                         .FirstOrDefault();
            if (v != default)
            {
                if(pi.PropertyType.IsGenericType && (v.Modes?.Length ?? 0) > 0)
                {
                    return v.Modes[0] == 2;
                }
                return v.Mode == 2;
            }
            return false;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions