Replies: 5 comments 1 reply
-
/cc @cartermp Do you know the best way to annotate a method like this? |
Beta Was this translation helpful? Give feedback.
-
I don't think it's possible to apply this attribute to elements of a tuple type. Might be good to file this as a suggestion under dotnet/csharplang. |
Beta Was this translation helpful? Give feedback.
-
Thanks @cartermp I've transferred the issue to the csharplang repo. |
Beta Was this translation helpful? Give feedback.
-
I'm not arguing for or against this request, but I will just point out what's currently available. Firstly, note that this already exists. This means you can call Secondly, the normal pattern for public static bool TryGetCustomAttribute<T>(MemberInfo member, [MaybeNullWhen(false)] out T attribute); From personal experience, I've found this is easier to use than returning a if (TryGetCustomAttribute<SomeAttribute>(member, out var attribute))
{
// use attribute
} |
Beta Was this translation helpful? Give feedback.
-
You can with tuples too: if (TryGetCustomAttribute<SomeAttribute>(member) is (true, {} attribute))
{
// use attribute
} Some people like And because that |
Beta Was this translation helpful? Give feedback.
-
I have a method called
TryGetCustomAttribute<TAttribute>(MemberInfo member)
That returns the Tuple:
(bool Success, TAttribute? Attribute)
How do i indicate that Attribute is not null when Success is true?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Beta Was this translation helpful? Give feedback.
All reactions