Редагувати

Поділитися через


HostProtectionResource Enum

Definition

Caution

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

Specifies categories of functionality potentially harmful to the host if invoked by a method or class.

This enumeration supports a bitwise combination of its member values.

public enum class HostProtectionResource
[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
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum HostProtectionResource
[System.Flags]
public enum HostProtectionResource
[<System.Flags>]
[<System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type HostProtectionResource = 
[<System.Flags>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type HostProtectionResource = 
[<System.Flags>]
type HostProtectionResource = 
Public Enum HostProtectionResource
Inheritance
HostProtectionResource
Attributes

Fields

Name Value Description
None 0

Exposes no host resources.

Synchronization 1

Exposes synchronization.

SharedState 2

Exposes state that might be shared between threads.

ExternalProcessMgmt 4

Might create or destroy other processes.

SelfAffectingProcessMgmt 8

Might exit the current process, terminating the server.

ExternalThreading 16

Creates or manipulates threads other than its own, which might be harmful to the host.

SelfAffectingThreading 32

Manipulates threads in a way that only affects user code.

SecurityInfrastructure 64

Exposes the security infrastructure.

UI 128

Exposes the user interface.

MayLeakOnAbort 256

Might cause a resource leak on termination, if not protected by a safe handle or some other means of ensuring the release of resources.

All 511

Exposes all host resources.

Examples

The following code example shows the use of the HostProtectionResource enumeration with the HostProtectionAttribute attribute. This example is part of a larger example provided for the HostProtectionAttribute class.

// 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.
// Exit the sample when an exception is thrown.

[HostProtection(SharedState=true,SelfAffectingProcessMgmt=true)]
[HostProtection(Resources=HostProtectionResource::SharedState|
HostProtectionResource::SelfAffectingProcessMgmt)]
static void Exit( String^ Message, int Code )
{
   Console::WriteLine( "\nFAILED: {0} {1}", Message, Code );
   Environment::ExitCode = Code;
   Environment::Exit( Code );
}
// 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);
}
' 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 Or _
    HostProtectionResource.SelfAffectingProcessMgmt)> _
Private Shared Sub [Exit](ByVal Message As String, ByVal Code As Integer)

    ' Exit the sample when an exception is thrown.
    Console.WriteLine((ControlChars.Lf & "FAILED: " & Message & " " & _
        Code.ToString()))
    Environment.ExitCode = Code
    Environment.Exit(Code)
End Sub

Remarks

Caution

Code Access Security (CAS) has been deprecated across all versions of .NET Framework and .NET. Recent versions of .NET do not honor CAS annotations and produce errors if CAS-related APIs are used. Developers should seek alternative means of accomplishing security tasks.

This enumeration is used by the HostProtectionAttribute attribute.

Applies to