/// <summary> /// Gets a value indicating whether GC transition should be suppressed on the given p/invoke. /// </summary> public static bool IsSuppressGCTransition(this MethodDesc method) { Debug.Assert(method.IsPInvoke); // Check SuppressGCTransition attribute if (method.HasSuppressGCTransitionAttribute()) { return(true); } MethodSignatureFlags unmanagedCallConv = method.GetPInvokeMethodMetadata().Flags.UnmanagedCallingConvention; if (unmanagedCallConv != MethodSignatureFlags.None) { return(false); } if (!(method is Internal.TypeSystem.Ecma.EcmaMethod ecmaMethod)) { return(false); } // Check UnmanagedCallConv attribute System.Reflection.Metadata.CustomAttributeValue <TypeDesc>?unmanagedCallConvAttribute = ecmaMethod.GetDecodedCustomAttribute("System.Runtime.InteropServices", "UnmanagedCallConvAttribute"); if (unmanagedCallConvAttribute == null) { return(false); } foreach (DefType defType in unmanagedCallConvAttribute.Value.EnumerateCallConvsFromAttribute()) { if (defType.Name == "CallConvSuppressGCTransition") { return(true); } } return(false); }