获取 .NET 方法返回值的属性数据 [英] Getting Attribute Data For Return Value of .NET Method

查看:54
本文介绍了获取 .NET 方法返回值的属性数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 MemberInfo 上调用 GetCustomAttributesData,这很好,因为我知道调用了哪个构造函数来初始化属性以及使用了哪些命名参数.

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.

如果我将 [return: ...] 放在一个方法上来属性返回值,我将无法获得 GetCustomAttributesData.我唯一可以使用的是 ReturnTypeCustomAttributes,它为我获取属性,而不是它们的数据.

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.

有没有办法通过反射获取方法返回值的属性数据?注意:在 MethodInfo 对象上使用 GetCustomAttributesData 不会返回返回值的属性.

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.

推荐答案

我想通了:

x.ReturnParameter.GetCustomAttributesData()

这篇关于获取 .NET 方法返回值的属性数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆