Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net AllowReversePInvokeCallsAttribute的作用是什么?_.net_Pinvoke - Fatal编程技术网

.net AllowReversePInvokeCallsAttribute的作用是什么?

.net AllowReversePInvokeCallsAttribute的作用是什么?,.net,pinvoke,.net,Pinvoke,我做过反向pInvokes,但没有使用此属性。我从文档中注意到,它是在3.5中添加的,但文档中没有提供如何使用它或描述它的功能的任何示例。有人能说出它的作用,并举例说明如何使用它以及何时需要它吗?不应该是: 此API支持.NET Framework基础架构,不支持 旨在直接从代码中使用 参考资料中的注释提供了一些见解: // To be used on methods that sink reverse P/Invoke calls. // This attribute is a CoreCLR

我做过反向pInvokes,但没有使用此属性。我从文档中注意到,它是在3.5中添加的,但文档中没有提供如何使用它或描述它的功能的任何示例。有人能说出它的作用,并举例说明如何使用它以及何时需要它吗?

不应该是:

此API支持.NET Framework基础架构,不支持 旨在直接从代码中使用


参考资料中的注释提供了一些见解:

// To be used on methods that sink reverse P/Invoke calls.
// This attribute is a CoreCLR-only security measure, currently ignored by the desktop CLR.
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public sealed class AllowReversePInvokeCallsAttribute : Attribute
{
    public AllowReversePInvokeCallsAttribute()
    {
    }
}
CoreCLR是驱动Silverlight的CLR版本。大沙箱。您在桌面版本中根本找不到它,但在Silverlight程序集中到处都可以找到它。示例是MS.Internal.FrameworkCallbacks类和System.Windows命名空间。用反射器看一看。意图很清楚,当CLR封送从本机到托管的调用时,它会检查是否预期调用托管方法