I'm using System.Reflection.Metadata to enumerate some assemblies and pull out some information. For instance, I need to locate a type and then get information about its properties (name and type). I can find the type, find the property, but I can't figure out how to determine the type of the property. Here's what I have so far:
using (Stream stream = File.OpenRead(assemblyPath))
using (PEReader reader = new PEReader(stream))
{
TypeDefinition type = ...;
var properties = (from handles in type.GetProperties()
let prop = metadata.GetPropertyDefinition(handles)
let accessors = prop.GetAccessors()
let getter = metadata.GetMethodDefinition(accessors.Getter)
where getter.Attributes.HasFlag(MethodAttributes.Public)
select new
{
Name = prop.Name,
//Type=prop. ??? getter. ??? What to do here?
});
foreach (var prop in properties)
yield return prop;
}
For now I will simply load up the type using actual reflection in order to get the properties. But I'd rather use the metadata stuff instead.
Aucun commentaire:
Enregistrer un commentaire