private static CustomAttributeBuilder GetMarshalAsAttribute(Type marshalTypeRef)
{
// CONSIDER: Caching some of the metadata loaded here
Type[] ctorParams = new Type[] { typeof(UnmanagedType) };
ConstructorInfo classCtorInfo = typeof(MarshalAsAttribute).GetConstructor(ctorParams);
CustomAttributeBuilder builder = new CustomAttributeBuilder(
classCtorInfo,
new object[] { UnmanagedType.CustomMarshaler },
new FieldInfo[] { typeof(MarshalAsAttribute).GetField("MarshalTypeRef") },
new object[] { marshalTypeRef });
return builder;
}