J'ai jeté un coup d'oeil au framework 2.0, j'ai quelques doléances, la version française est en bas.
I've just downloaded the preview of the 2.0 framework now available in a
standalone distrubtion, without VS Whidbey, on MSDN.
As a developer of an AOP tool, and maintainer of the low layer of this tool,
my first thought was to take a look into the System.Reflection namespace.
If few things are better than in the 1.1, this is still insufficient. The
instrumentation part of the framework has been undervalued since the first
versions.
In the good points of this tech preview, we find the ability to get the
details of the creation of Custom Attributes.
This is done by using a static method of the new type
System.Reflection.CustomAttributeData :
public static IList!1<CustomAttributeData> GetCustomAttributes(
MemberInfo target
);
Good job with the IList, instead of an ArrayList or something else.
However, a simple array would have been enough. For more details, take a look here :
ms-help://MS.NETFramework.v20.en/cpref/html/T_System_Reflection_CustomAttributeData_Members.htm
The next lack concerns the body of the methods. For the moment, the good point is the new type :
System.Reflection.MethodBody
But it is very incomplete. In an assembly, exceptions and instructions are stored in different places,
this is why we found here methods to access data separately.
The exception part is clean, with read access to start and end offset of
clauses, the type of the exception in case of a catch handler, etc.
However, the instruction part is very, very, very, insufficient.
The only method is
public byte[] GetILAsByteArray();
I want to be able to manipulate instructions ! It is not much, and an
Instruction type would be quite simple to write :
public sealed class Instruction {
private OpCode m_opCode;
private uint m_offset;
private object m_operand;
//...
}
So I ask for a method :
public Instruction[] GetInstructions();
In the MethodBody type, or, if you want to do it in a "generic way",
public IList!1<Instruction> GetInstructions();
Still talking about methods details, I want to be able to read p/invoke
data, like the entry point or the library used. I haven't found anyway to
read this.
This should be enough for this time,
Sorry for my poor English.
----------------------------------------------------------------------------
Je viens de télécharger la preview du framework 2.0 maintenant disponible en
stand-alone sur la MSDN, sans l'ami VS Whidbey.
En tant que co-développeur d'un outil d'AOP, et responsable de la couche
basse de ce dernier, ma première envie fut d'aller jeter un coup d'oil au
namespace System.Reflection. Il y a du progrès, mais ce n'est nettement pas
suffisant. La partie instrumentation du framework est minorée depuis sa
création. C'est plus que dommage.
Dans les nouvelles fonctionnalités qui vont bien, la possibilité d'obtenir
le détail des CustomAttributes. Cela se fait par le biais d'une méthode
statique de la classe CustomAttributeData :
public static IList!1<CustomAttributeData> GetCustomAttributes(
MemberInfo target
);
Bravo pour le IList au passage, plutôt qu'un ArrayList ou autre.
Cependant, n'y aurait t'il pas ici un petit excès de zèle, un simple tableau eu suffit.
Pour des détails supplémentaires sur cette fonctionnalité, je vous renvoie vers la documentation :
ms-help://MS.NETFramework.v20.en/cpref/html/T_System_Reflection_CustomAttributeData_Members.htm
Voila pour un gros manque de la 1.0. Le second, plus évident, c'est le corps
des méthodes. Pour l'instant, la seule amélioration, c'est la présence d'un objet
System.Reflection.MethodBody
Il faut savoir que dans une assembly, les exceptions et les instructions
sont stockées dans des endroits différents. Pour l'instant, cet objet nous
permet d'accéder proprement aux exceptions, ie les offsets de début et de
fin des clauses, le type de l'exception, etc. Stupeur et tremblements, pour
les instructions, cet objet expose seulement la méthode
public byte[] GetILAsByteArray();
C'est nettement insuffisant. Je veux que l'on puisse accéder de manière
standardisée aux instructions. Ce n'est pas grand-chose pourtant, un objet
Instruction est simple à écrire.
public sealed class Instruction {
private OpCode m_opCode;
private uint m_offset;
private object m_operand;
//...
}
Je souhaiterais donc voir apparaître la méthode
public Instruction[] GetInstructions();
Voir, si on continue dans le zèle,
public IList!1<Instruction> GetInstructions();
Toujours dans le cadre du détail des méthodes, en cas de p/invoke, je veux
pouvoir avoir accès aux données du p/invoke, comme la librairie, le point
d'entrée, etc. Car si on définit une méthode p/invoke par un attribut
DllImport dans le code, il n'en reste rien dans l'assembly produite.
Voila, déjà ça ce serait pas mal.