I'm not exactly sure what is it you're asking. I assume that by
GetCustomAttributes, you mean a call at application runtime to
System.Reflection.*.GetCustomAttributes or to
Attribute.GetCustomAttribute in order to instantiate them.

It is indeed a bit costly, but it's worth profiling whether or not it
is actually consuming or not. You could also try to use the
GetCustomAttributeData methods that are not instantiating attributes,
but return the actual values that would be used to instantiate the
attributes.

Caching would also work. In any case there's nothing in the IL to
speed things up. If your weaving process is aware of all the
attributes, you could always serialize the data retrieved by Cecil
into a custom version of the data you need and inject code to access
it.

On Wednesday, December 8, 2010, Jeff Nevins <[email protected]> wrote:
> Hi,
>
> Is there a way I can load a CustomAttribute directly in IL? I would be
> calling GetCustomAttributes many of thousands of times otherwise and I
> know there is a big performance hit in that method. Is there any way
> to load the attribute quickly? Or should I just cache the result of
> GetCustomAttributes?
>
> Thanks.
>
> --
> --
> mono-cecil

-- 
--
mono-cecil

Reply via email to