>I can not find any examples on how to
>work with the CustomAttributeData object nor any documentation on the object
>or process of using reflection to retrieve information on assemblies you have
>no intention of instantiating. Can anyone help me with the process of using
>reflection in the ReflectionOnly universe for retrieving Attribute info
>(DescriptionAttribute specificall) ?
Something like this
// Preload the System assembly dependency
Assembly.ReflectionOnlyLoad(typeof(DescriptionAttribute).Assembly.FullName);
// Load your assembly containing the method with the description
Assembly a = Assembly.ReflectionOnlyLoadFrom("your.dll");
MethodInfo mi = a.GetType("´TheClass").GetMethod("TheMethod");
foreach (CustomAttributeData cad in
CustomAttributeData.GetCustomAttributes(mi))
{
// Verify the attribute type is correct and that the
// parameterless constructor wasn't used.
if (cad.Constructor.DeclaringType.FullName ==
"System.ComponentModel.DescriptionAttribute" &&
cad.Constructor.GetParameters().Length > 0 &&
cad.ConstructorArguments[0].ArgumentType == typeof(string))
{
Console.WriteLine((string)cad.ConstructorArguments[0].Value);
}
}
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
William Wallace - 29 Jul 2005 09:16 GMT
thx, thats just where i got stuck :)

Signature
William Wallace
DarkNoir@community.microsoft.com
> >I can not find any examples on how to
> >work with the CustomAttributeData object nor any documentation on the object
[quoted text clipped - 27 lines]
>
> Mattias