简体   繁体   中英

Can a static class extension be inlined?

I have a tendency (throw back to c++ days) to add inlining hints to small methods, for example:

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Add(this IProject @this, IComponent component)
{
    @this.Components.Add(component);
}

I was wondering whether a static class extension-methods could be inlined in the first place?

Static methods can be inlined. See here for information on how to check if a method is being inlined. Extension methods are no different from normal static methods; in IL they are just decorated with a System.Runtime.CompilerServices.ExtensionAttribute , so they will be treated the same by the JIT.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM