__DynamicallyInvokableAttribute

It is undocumented, but it looks like one of the optimizations in .NET 4.5. It appears to be used to prime the reflection type info cache, making subsequent reflection code on common framework types run faster. There’s a comment about it in the Reference Source for System.Reflection.Assembly.cs, RuntimeAssembly.Flags property:

// Each blessed API will be annotated with a "__DynamicallyInvokableAttribute".
// This "__DynamicallyInvokableAttribute" is a type defined in its own assembly.
// So the ctor is always a MethodDef and the type a TypeDef.
// We cache this ctor MethodDef token for faster custom attribute lookup.
// If this attribute type doesn't exist in the assembly, it means the assembly
// doesn't contain any blessed APIs.
Type invocableAttribute = GetType("__DynamicallyInvokableAttribute", false); 
if (invocableAttribute != null) 
{ 
    Contract.Assert(((MetadataToken)invocableAttribute.MetadataToken).IsTypeDef); 
    ConstructorInfo ctor = invocableAttribute.GetConstructor(Type.EmptyTypes); 
    Contract.Assert(ctor != null); 
    int token = ctor.MetadataToken;
    Contract.Assert(((MetadataToken)token).IsMethodDef); 
    flags |= (ASSEMBLY_FLAGS)token & ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_TOKEN_MASK; 
}
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑

%d bloggers like this: