次の方法で共有


AppDomain.SetData メソッド

指定したアプリケーション ドメイン プロパティに、指定した値を割り当てます。

Public Overridable Sub SetData( _
   ByVal name As String, _   ByVal data As Object _) Implements _AppDomain.SetData
[C#]
public virtual void SetData(stringname,objectdata);
[C++]
public: virtual void SetData(String* name,Object* data);
[JScript]
public function SetData(
   name : String,data : Object);

パラメータ

  • name
    アプリケーション ドメイン プロパティの名前。
  • data
    name プロパティに設定する値。

実装

_AppDomain.SetData

例外

例外の種類 条件
AppDomainUnloadedException 操作が、アンロードされたアプリケーション ドメインで試行されています。
SecurityException 呼び出し元に、正しいアクセス許可がありません。要件のセクションを参照してください。

解説

このメソッドを使用すると、 AppDomain のこのインスタンスのプロパティを記述している名前とデータの組み合わせの内部キャッシュにエントリを挿入したり、その値を編集したりできます。

キャッシュには、アプリケーション ドメインの作成時に挿入される定義済みのシステム エントリが自動的に格納されます。このメソッドを使用してシステム エントリを挿入したり、編集したりすることはできません。この値を検査するには、 GetData メソッドまたは同等の AppDomainSetup プロパティを使用できます。この詳細については、 GetData メソッドの「解説」を参照してください。この値を編集するには、該当する AppDomainSetup のプロパティを使用します。

このメソッドを使用すると、独自のユーザー定義の名前とデータの組み合わせを挿入または編集できます。値を検査するには、 GetData メソッドを使用します。

使用例

 
Imports System
Imports System.Reflection



Class ADGetData
   
   
   Public Shared Sub Main()
      ' appdomain setup information
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      
      'set predefined system variable application name
      Dim dataName As [String] = "APP_NAME"
      Dim setappname As [String] = "MyApplication"
      currentDomain.SetData(dataName, setappname)
      
      'Create a new value pair for the appdomain
      Dim dataValue As [String] = "ADVALUE"
      Dim advalue As Int32 = 6
      currentDomain.SetData(dataValue, advalue)
      
      'get the value specified in the setdata method
      Console.WriteLine((" ADVALUE is: " + currentDomain.GetData("ADVALUE")))
      
      'get system value specified at appdomainsetup
      Console.WriteLine(("System value for application name:" + currentDomain.GetData("APP_NAME")))
   End Sub 'Main 
End Class 'ADGetData

[C#] 
using System;
using System.Reflection;

class ADGetData 
{

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

        //set predefined system variable application name
        String dataName = "APP_NAME";
        String setappname = "MyApplication";
        currentDomain.SetData(dataName, setappname);

        //Create a new value pair for the appdomain
        String dataValue = "ADVALUE";
        Int32 advalue = 6;
        currentDomain.SetData(dataValue, advalue);

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

        //get system value specified at appdomainsetup
        Console.WriteLine("System value for application name:" + currentDomain.GetData("APP_NAME"));
        
    }
   
    
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;

int main() {
   // appdomain setup information
   AppDomain*  currentDomain = AppDomain::CurrentDomain;

   //set predefined system variable application name
   String*  dataName = S"APP_NAME";
   String*  setappname = S"MyApplication";
   currentDomain->SetData(dataName, setappname);

   //Create a new value pair for the appdomain
   String*  dataValue = S"ADVALUE";
   Int32 advalue = 6;
   currentDomain->SetData(dataValue, __box(advalue));

   //get the value specified in the setdata method
   Console::WriteLine(S" ADVALUE is: {0}", currentDomain->GetData(S"ADVALUE"));

   //get system value specified at appdomainsetup
   Console::WriteLine(S"System value for application name: {0}", currentDomain->GetData(S"APP_NAME"));

}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

AppDomain クラス | AppDomain メンバ | System 名前空間 | GetData