如何将自定义属性添加到DynamicMethod生成的方法中? [英] How to add Custom Attributes to a DynamicMethod-generated method?

查看:147
本文介绍了如何将自定义属性添加到DynamicMethod生成的方法中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩 DynamicMethod 表达式树'编译(使用

I was playing around with DynamicMethod and Expression Trees' Compilation (which uses DynamicMethod internally).

然后我想知道是否有一种方法可以将自定义属性添加到生成的方法中。我用谷歌搜索,但是找不到方法。我知道可以使用CodeDom,但是我想使用 DynamicMethod

I then wondered if there is a way to add a custom attribute to the generated method. I googled about it, but I couldn't find a way. I know that it's possible to do using CodeDom, but I want to use DynamicMethod.

有人提到类型描述符,但我不确定是否有帮助。

Someone mentioned Type Descriptor, but I'm not sure if it helps.

有人知道一种为使用 DynamicMethod 生成的方法定义自定义属性的方法吗?

Does anyone knows a way to define custom attributes to methods generated using DynamicMethod?

推荐答案

没有办法在DynamicMethods上设置自定义属性,来自MSDN

No there is no way to set custom attributes on DynamicMethods, from MSDN:


$ b不支持自定义属性$ b动态方法或其参数。

Custom attributes are not supported on dynamic methods or their parameters.

这篇关于如何将自定义属性添加到DynamicMethod生成的方法中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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