AppDomain.GetData(String) 方法

定義

針對指定之名稱取得儲存在目前應用程式定義域中的值。

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

參數

name
String

預先定義的應用程式定義域屬性的名稱,或是已經定義的應用程式定義域屬性的名稱。

傳回

name 屬性的值;如果這個屬性不存在,則為 null

實作

例外狀況

namenull

嘗試對卸載的應用程式定義域執行作業。

範例

下列範例會建立新的應用程式域、設定網域的系統提供值,並為定義域新增新的值組。 然後,此範例會示範如何使用 GetData 方法來從這些值組擷取資料,並將其顯示至主控台。

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

備註

使用這個方法,擷取描述這個 實例 AppDomain 屬性之名稱資料組內部快取中的專案值。 請注意,與索引鍵/值組名稱的 比較 name 會區分大小寫。

快取會自動包含建立應用程式域時所插入的預先定義系統專案。 您可以使用 方法或對等 AppDomainSetup 的屬性來檢查其值 GetData

您可以使用 方法插入或修改自己的使用者定義名稱資料組 SetData ,並使用 方法檢查其值 GetData

下表描述 name 每個預先定義的系統專案及其對應的 AppDomainSetup 屬性。

'name' 的值 屬性
「APPBASE」 AppDomainSetup.ApplicationBase
「APP_CONFIG_FILE」 AppDomainSetup.ConfigurationFile
「APP_LAUNCH_URL」 (沒有屬性)

「APP_LAUNCH_URL」 代表使用者原本在重新導向之前所要求的 URL。 只有在應用程式已透過瀏覽器啟動時才可使用。 並非所有瀏覽器都提供此值。
「APP_NAME」 AppDomainSetup.ApplicationName
「BINPATH_PROBE_ONLY」 AppDomainSetup.PrivateBinPathProbe
「CACHE_BASE」 AppDomainSetup.CachePath
「CODE_DOWNLOAD_DISABLED」 AppDomainSetup.DisallowCodeDownload
「DEV_PATH」 (沒有屬性)
「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」,或應用程式特定的字串 AppDomainSetup.LicenseFile
「LOADER_OPTIMIZATION」 AppDomainSetup.LoaderOptimization
「LOCATION_URI」 (沒有屬性)
「PRI加值稅E_BINPATH」 AppDomainSetup.PrivateBinPath
「REGEX_DEFAULT_MATCH_TIMEOUT」 Regex.MatchTimeout

「REGEX_DEFAULT_MATCH_TIMEOUT」 不是系統專案,而且可以藉由呼叫 SetData 方法來設定其值。
「SHADOW_COPY_DIRS」 AppDomainSetup.ShadowCopyDirectories

適用於

另請參閱