Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thanks and a quick observation #1

Open
fuocor opened this issue Apr 29, 2019 · 0 comments
Open

Thanks and a quick observation #1

fuocor opened this issue Apr 29, 2019 · 0 comments

Comments

@fuocor
Copy link

fuocor commented Apr 29, 2019

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;
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant