This is a very bad solution under most circumstances - NORMALLY you would want your 
program not to run under the profiler. I face similar limitations in other situations 
(the need to replace a method's bytecode at load time), and I found having the 
profiler running during program run not to be acceptable.

Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)



> -----Original Message-----
> From: Schmied Fabian [mailto:[EMAIL PROTECTED] 
> Sent: Montag, 24. März 2003 13:04
> To: [EMAIL PROTECTED]
> Subject: Re: [ADVANCED-DOTNET] Adding a custom attribute to a type
> 
> 
> You can write an unmanaged profiler that adds the attribute 
> at load time. Have a look at Profiling.doc and Metadata 
> Unmanaged.doc/Assembly Metadata Unmanaged.doc in your 
> FrameworkSDK\Tool Developers Guide\Docs folder.
>  
> You will have to:
> Write a COM component implementing ICorProfilerCallback 
> Intercept the ModuleLoadFinished or ClassLoadFinished events 
> Get the IMetaDataAssemblyEmit and IMetaDataEmit interfaces 
> for the module you want to manipulate Add a MemberRef to the 
> attribute's constructor (and probably an AssemblyRef and 
> TypeRef as well) Finally add the custom attribute
>  
> This is just a rough outline, so be sure to read the 
> documents I mentioned.
>  
> Fabian Schmied
> 
>       -----Ursprüngliche Nachricht----- 
>       Von: Pierre [mailto:[EMAIL PROTECTED] 
>       Gesendet: Mo 24.03.2003 11:10 
>       An: [EMAIL PROTECTED] 
>       Cc: 
>       Betreff: [ADVANCED-DOTNET] Adding a custom attribute to a type
>       
>       
>       Hello,
>       I have an assembly containing a Type and I need to add 
> an attribute to a
>       method of that type at run-time. I tryied to look inside
>       System.Reflection.Emit but I didn't found the way of 
> adding the custom
>       attribute of an already created type.
>       
>       Someone suggested that there are some unmanaged APIs to 
> do that but I didn't
>       found any document talking about them.
>       
>       Thanks for any help,
>       Pierre
> 
> 

===================================
This list is hosted by DevelopMentor®  http://www.develop.com
You may be interested in Guerrilla .NET, 24 March 2003, in London and Boston
http://www.develop.com/courses/gdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to