JasonBock
JasonBock

Reputation: 1001

Getting Attribute Data For Return Value of .NET Method

I can call GetCustomAttributesData on a MemberInfo, which is nice because I know which constructor was called to initialize the attribute and what named arguments were used.

If I put [return: ...] on a method to attribute the return value, I can't get to GetCustomAttributesData. The only thing I can use is ReturnTypeCustomAttributes, which gets me the attributes, not their data.

Is there any way to get the attribute data via reflection for a return value of a method? Note: using GetCustomAttributesData on the MethodInfo object doesn't return attributes for the return value.

Upvotes: 3

Views: 763

Answers (1)

JasonBock
JasonBock

Reputation: 1001

I figured it out:

x.ReturnParameter.GetCustomAttributesData()

Upvotes: 3

Related Questions