AppDomain.GetData(String) AppDomain.GetData(String) AppDomain.GetData(String) AppDomain.GetData(String) Method

定义

为指定名称获取存储在当前应用程序域中的值。Gets the value stored in the current application domain for the specified name.

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

参数

name
String String String String

预定义应用程序域属性的名称,或已定义的应用程序域属性的名称。The name of a predefined application domain property, or the name of an application domain property you have defined.

返回

name 属性的值,或 null(如果属性不存在)。The value of the name property, or null if the property does not exist.

实现

异常

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

示例

下面的示例创建一个新的应用程序域,为域设置系统提供的值,并为该域添加一个新的值对。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. 然后,该示例演示如何使用GetData方法来检索这些值对中的数据,并将其显示在控制台中。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
 */

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

注解

使用此方法检索名称数据对的内部缓存中的项的值,这些名称数据对用于描述此实例的AppDomain属性。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. 请注意, name与键值对的名称比较是区分大小写的。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. 可以通过GetData方法或等效AppDomainSetup属性检查其值。You can inspect their values with the GetData method, or the equivalent AppDomainSetup properties.

可以通过SetData方法插入或修改自己的用户定义的名称数据对,并GetData通过方法检查其值。You can insert or modify your own user defined name-data pairs with the SetData method and inspect their values with the GetData method.

下表描述name了每个预定义系统项及其对应AppDomainSetup属性的。The following table describes the name of each predefined system entry and its corresponding AppDomainSetup property.

"Name" 的值Value of 'name' PropertyProperty
APPBASE"APPBASE" AppDomainSetup.ApplicationBase
"APP_CONFIG_FILE""APP_CONFIG_FILE" AppDomainSetup.ConfigurationFile
"APP_LAUNCH_URL""APP_LAUNCH_URL" (无属性)(no property)

"APP_LAUNCH_URL" 代表用户在任何重定向之前最初请求的 URL。"APP_LAUNCH_URL" represents the URL originally requested by the user, before any redirection. 仅当使用浏览器(如 Internet Explorer)启动应用程序时,此功能才可用。It is available only when the application has been launched with a browser such as Internet Explorer. 并非所有浏览器都提供此值。Not all browsers provide this value.
"APP_NAME""APP_NAME" AppDomainSetup.ApplicationName
"BINPATH_PROBE_ONLY""BINPATH_PROBE_ONLY" AppDomainSetup.PrivateBinPathProbe
"CACHE_BASE""CACHE_BASE" AppDomainSetup.CachePath
"CODE_DOWNLOAD_DISABLED""CODE_DOWNLOAD_DISABLED" AppDomainSetup.DisallowCodeDownload
"DEV_PATH""DEV_PATH" (无属性)(no property)
"DISALLOW_APP""DISALLOW_APP" AppDomainSetup.DisallowPublisherPolicy
"DISALLOW_APP_BASE_PROBING""DISALLOW_APP_BASE_PROBING" AppDomainSetup.DisallowApplicationBaseProbing
"DISALLOW_APP_REDIRECTS""DISALLOW_APP_REDIRECTS" AppDomainSetup.DisallowBindingRedirects
"DYNAMIC_BASE""DYNAMIC_BASE" AppDomainSetup.DynamicBase
"FORCE_CACHE_INSTALL""FORCE_CACHE_INSTALL" AppDomainSetup.ShadowCopyFiles
"LICENSE_FILE" 或特定于应用程序的字符串"LICENSE_FILE", or an application-specific string AppDomainSetup.LicenseFile
"LOADER_OPTIMIZATION""LOADER_OPTIMIZATION" AppDomainSetup.LoaderOptimization
"LOCATION_URI""LOCATION_URI" (无属性)(no property)
"PRIVATE_BINPATH""PRIVATE_BINPATH" AppDomainSetup.PrivateBinPath
"REGEX_DEFAULT_MATCH_TIMEOUT""REGEX_DEFAULT_MATCH_TIMEOUT" Regex.MatchTimeout

"REGEX_DEFAULT_MATCH_TIMEOUT" 不是系统项,可以通过调用SetData方法来设置其值。"REGEX_DEFAULT_MATCH_TIMEOUT" is not a system entry, and its value can be set by calling the SetData method.
"SHADOW_COPY_DIRS""SHADOW_COPY_DIRS" AppDomainSetup.ShadowCopyDirectories

安全性

FileIOPermission
如果属性适用于路径,则用于访问路径本身中的信息。for access to the information in the path itself, if the property applies to a path. 关联的枚举:PathDiscoveryAssociated enumeration: PathDiscovery.

适用于

另请参阅