Upraviť

Zdieľať cez


AppDomain.GetData(String) Method

Definition

Gets the value stored in the current application domain for the specified name.

public:
 System::Object ^ GetData(System::String ^ name);
public:
 virtual System::Object ^ GetData(System::String ^ name);
public object? GetData (string name);
public object GetData (string name);
member this.GetData : string -> obj
abstract member GetData : string -> obj
override this.GetData : string -> obj
Public Function GetData (name As String) As Object

Parameters

name
String

The name of a predefined application domain property, or the name of an application domain property you have defined.

Returns

The value of the name property, or null if the property does not exist.

Implements

Exceptions

name is null.

The operation is attempted on an unloaded application domain.

Examples

The following example creates a new application domain, sets a system-provided value for the domain, and adds a new value pair for the domain. The example then demonstrates how to use the GetData method to retrieve the data from these value pairs and display them to the console.

using namespace System;
using namespace System::Reflection;

int main()
{
   // appdomain setup information
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   
   //Create a new value pair for the appdomain
   currentDomain->SetData( "ADVALUE", "Example value" );
   
   //get the value specified in the setdata method
   Console::WriteLine( "ADVALUE is: {0}", currentDomain->GetData( "ADVALUE" ) );
   
   //get a system value specified at appdomainsetup
   Console::WriteLine( "System value for loader optimization: {0}", 
      currentDomain->GetData( "LOADER_OPTIMIZATION" ) );
}

/* This code example produces the following output:

ADVALUE is: Example value
System value for loader optimization: NotSpecified
 */
using System;
using System.Reflection;

class ADGetData
{
    public static void Main()
    {
        // appdomain setup information
        AppDomain currentDomain = AppDomain.CurrentDomain;

        //Create a new value pair for the appdomain
        currentDomain.SetData("ADVALUE", "Example value");

        //get the value specified in the setdata method
        Console.WriteLine("ADVALUE is: " + currentDomain.GetData("ADVALUE"));

        //get a system value specified at appdomainsetup
        Console.WriteLine("System value for loader optimization: {0}",
            currentDomain.GetData("LOADER_OPTIMIZATION"));
    }
}

/* This code example produces the following output:

ADVALUE is: Example value
System value for loader optimization: NotSpecified
 */
open System

// appdomain setup information
let currentDomain = AppDomain.CurrentDomain

//Create a new value pair for the appdomain
currentDomain.SetData("ADVALUE", "Example value")

//get the value specified in the setdata method
currentDomain.GetData "ADVALUE"
|> printfn "ADVALUE is: %O"

//get a system value specified at appdomainsetup
currentDomain.GetData "LOADER_OPTIMIZATION"
|> printfn "System value for loader optimization: %O"

(* This code example produces the following output:

ADVALUE is: Example value
System value for loader optimization: NotSpecified
*)
Imports System.Reflection

Class ADGetData   
   
   Public Shared Sub Main()
      ' appdomain setup information
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      
      'Create a new value pair for the appdomain
      currentDomain.SetData("ADVALUE", "Example value")
      
      'get the value specified in the setdata method
      Console.WriteLine(("ADVALUE is: " & currentDomain.GetData("ADVALUE")))
      
      'get a system value specified at appdomainsetup
      Console.WriteLine("System value for loader optimization: {0}", _
         currentDomain.GetData("LOADER_OPTIMIZATION"))

   End Sub 
End Class 

' This code example produces the following output:
'
'ADVALUE is: Example value
'System value for loader optimization: NotSpecified

Remarks

Use this method to retrieve the value of an entry in an internal cache of name-data pairs that describe properties of this instance of AppDomain. Note that the comparison of name with the name of key-value pairs is case-sensitive.

The cache automatically contains predefined system entries that are inserted when the application domain is created. You can inspect their values with the GetData method, or the equivalent AppDomainSetup properties.

You can insert or modify your own user defined name-data pairs with the SetData method and inspect their values with the GetData method.

The following table describes the name of each predefined system entry and its corresponding AppDomainSetup property.

Value of 'name' Property
"APPBASE" AppDomainSetup.ApplicationBase
"APP_CONFIG_FILE" AppDomainSetup.ConfigurationFile
"APP_LAUNCH_URL" (no property)

"APP_LAUNCH_URL" represents the URL originally requested by the user, before any redirection. It is available only when the application has been launched with a browser. Not all browsers provide this value.
"APP_NAME" AppDomainSetup.ApplicationName
"BINPATH_PROBE_ONLY" AppDomainSetup.PrivateBinPathProbe
"CACHE_BASE" AppDomainSetup.CachePath
"CODE_DOWNLOAD_DISABLED" AppDomainSetup.DisallowCodeDownload
"DEV_PATH" (no property)
"DISALLOW_APP" AppDomainSetup.DisallowPublisherPolicy
"DISALLOW_APP_BASE_PROBING" AppDomainSetup.DisallowApplicationBaseProbing
"DISALLOW_APP_REDIRECTS" AppDomainSetup.DisallowBindingRedirects
"DYNAMIC_BASE" AppDomainSetup.DynamicBase
"FORCE_CACHE_INSTALL" AppDomainSetup.ShadowCopyFiles
"LICENSE_FILE", or an application-specific string AppDomainSetup.LicenseFile
"LOADER_OPTIMIZATION" AppDomainSetup.LoaderOptimization
"LOCATION_URI" (no property)
"PRIVATE_BINPATH" AppDomainSetup.PrivateBinPath
"REGEX_DEFAULT_MATCH_TIMEOUT" Regex.MatchTimeout

"REGEX_DEFAULT_MATCH_TIMEOUT" is not a system entry, and its value can be set by calling the SetData method.
"SHADOW_COPY_DIRS" AppDomainSetup.ShadowCopyDirectories

Applies to

See also