How to add Custom Attributes to a DynamicMethod-generated method?

别等时光非礼了梦想. 提交于 2020-01-05 03:27:08

问题


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

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.

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


回答1:


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

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



来源:https://stackoverflow.com/questions/1145123/how-to-add-custom-attributes-to-a-dynamicmethod-generated-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!