閱讀英文版本

分享方式:


HostProtectionResource 列舉

定義

警告

Code Access Security is not supported or honored by the runtime.

指定功能的分類,如果方法或類別叫用這些功能,則可能對主機有害。

此列舉支援其成員值的位元組合。

C#
[System.Flags]
[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public enum HostProtectionResource
C#
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum HostProtectionResource
C#
[System.Flags]
public enum HostProtectionResource
繼承
HostProtectionResource
屬性

欄位

名稱 Description
All 511

公開 (Expose) 所有主機資源。

ExternalProcessMgmt 4

可能建立或終結其他處理序。

ExternalThreading 16

建立或管理除了其自身之外的執行緒,這些執行緒可能對主機有害。

MayLeakOnAbort 256

如果未受安全控制代碼或某些確保資源釋放的其他方法保護,可能會導致終止時的資源流失。

None 0

未公開任何主機資源。

SecurityInfrastructure 64

公開安全性基礎結構。

SelfAffectingProcessMgmt 8

可能結束目前的處理序,終止伺服器。

SelfAffectingThreading 32

以只影響使用者程式碼的方式管理執行緒。

SharedState 2

公開可能在執行緒之間共用的狀態。

Synchronization 1

公開同步處理。

UI 128

公開使用者介面。

範例

下列程式代碼範例示範搭配 屬性使用 HostProtectionResource 列舉 HostProtectionAttribute 。 此範例是針對 類別提供的較大範例的 HostProtectionAttribute 一部分。

C#
// Use the enumeration flags to indicate that this method exposes 
// shared state and self-affecting process management.
// Either of the following attribute statements can be used to set the
// resource flags.
[HostProtectionAttribute(SharedState = true, 
    SelfAffectingProcessMgmt = true)]
[HostProtectionAttribute(Resources = HostProtectionResource.SharedState |
     HostProtectionResource.SelfAffectingProcessMgmt)]
private static void Exit(string Message, int Code)
{
    // Exit the sample when an exception is thrown.
    Console.WriteLine("\nFAILED: " + Message + " " + Code.ToString());
    Environment.ExitCode = Code;
    Environment.Exit(Code);
}

備註

注意

程式代碼存取安全性 (CAS) 在所有版本的 .NET Framework 和 .NET 中已被取代。 使用 CAS 相關 API 時,最新版本的 .NET 不會接受 CAS 批注,併產生錯誤。 開發人員應尋求替代方案來完成安全性工作。

屬性會 HostProtectionAttribute 使用此列舉。

適用於

產品 版本 (已過時)
.NET (6, 7, 8, 9)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1 (5, 6, 7, 8, 9)