語言

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 是該財產是否不存在。

實作

例外狀況

name 是 null。

此操作嘗試在未載入的應用程式域上執行。

範例

以下範例建立一個新的應用域,設定系統提供的該域值,並新增一對值。 接著範例示範如何使用此 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 鍵值對名稱的比較是區分大小寫的。

快取會自動包含預先定義的系統條目,並在建立應用程式域時插入。 你可以用該 GetData 方法或等效 AppDomainSetup 性質檢查它們的數值。

你可以用這個 SetData 方法插入或修改你自己定義的名稱資料對,並用這個 GetData 方法檢查它們的值。

下表描述 name 每個預定義系統條目及其對應 AppDomainSetup 屬性。

「名稱」的價值 房產
「APPBASE」 AppDomainSetup.ApplicationBase
「APP_CONFIG_FILE」 AppDomainSetup.ConfigurationFile
「APP_LAUNCH_URL」 (無財產)

「APP_LAUNCH_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」 (無財產)
「PRIVATE_BINPATH」 AppDomainSetup.PrivateBinPath
「REGEX_DEFAULT_MATCH_TIMEOUT」 Regex.MatchTimeout

「REGEX_DEFAULT_MATCH_TIMEOUT」不是系統條目,其值可透過呼叫 SetData 方法設定。
「SHADOW_COPY_DIRS」 AppDomainSetup.ShadowCopyDirectories

適用於

另請參閱