Re: [ADVANCED-DOTNET] Adding a custom attribute to a type

2003-03-26 Thread Pierre Greborio
  I am reading the documentation suggested and it isn't
 required to run
 under
  profiler since you can read and add new MetaData elements starting
  from an instance of IMetaDataDispenser.

 Hm, you said you wanted to add the attribute at runtime. Did
 you find a way to get the Dispenser interface of the runtime
 so you can access the CLR's internal data structures? Because
 if not, the dispenser is more of a static tool.

It seems possible, but I continue to investigate. From the
IMetaDataDispenser I can get IMetaDataEmit (through OpenScope method) and
then add the custom attribute. I'm working on and I will say here how the
app works

Thanks,
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


Re: [ADVANCED-DOTNET] Adding a custom attribute to a type

2003-03-24 Thread Thomas Tomiczek
Not possible to my knowledge.

What COULD work is that the type implements cutom type and returns an instance of the 
attribute when asked for - BUT - the normal mechanism uses reflection, and it is not 
possible to add an attribute to this at runtime.

Regards

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



 -Original Message-
 From: Pierre [mailto:[EMAIL PROTECTED] 
 Sent: Montag, 24. März 2003 11:11
 To: [EMAIL PROTECTED]
 Subject: [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

===
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


Re: [ADVANCED-DOTNET] Adding a custom attribute to a type

2003-03-24 Thread Thomas Tomiczek
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


Re: [ADVANCED-DOTNET] Adding a custom attribute to a type

2003-03-24 Thread Schmied Fabian
You are right, it is a limitation in that 
  1) you can only use one profiler at a time
  2) attaching the profiler is somewhat tedious
  3) the unmanaged APIs are less than friendly to be used.

But so far it is the only solution to runtime-manipulation of existing code and 
metadata (unless I am missing something). Does anyone know, why exactly it isn't 
possible to turn a loaded assembly/module/type into a dynamic assembly/module/type? 
Also, if it were possible to implement a custom loader, life would be much easier 
regarding runtime code extension.

Fabian Schmied

-Ursprngliche Nachricht-
Von:Thomas Tomiczek [mailto:[EMAIL PROTECTED]
Gesendet:   Mo 24.03.2003 14:04
An: [EMAIL PROTECTED]
Cc: 
Betreff:Re: [ADVANCED-DOTNET] Adding a custom attribute to a type

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)

===
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


Re: [ADVANCED-DOTNET] Adding a custom attribute to a type

2003-03-24 Thread Pierre
Hello,
I am reading the documentation suggested and it isn't required to run under
profiler since you can read and add new MetaData elements starting from an
instance of IMetaDataDispenser.
Thanks,
Pierre
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
===
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


Re: [ADVANCED-DOTNET] Adding a custom attribute to a type

2003-03-24 Thread Fabian Schmied
 I am reading the documentation suggested and it isn't required to run
under
 profiler since you can read and add new MetaData elements starting from an
 instance of IMetaDataDispenser.

Hm, you said you wanted to add the attribute at runtime. Did you find a way
to get the Dispenser interface of the runtime so you can access the CLR's
internal data structures? Because if not, the dispenser is more of a static
tool.

Fabian

===
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