Uređivanje

Dijeli putem


AppDomain.SetData Method

Definition

Assigns a value to an application domain property.

Overloads

SetData(String, Object)

Assigns the specified value to the specified application domain property.

SetData(String, Object, IPermission)

Assigns the specified value to the specified application domain property, with a specified permission to demand of the caller when the property is retrieved.

SetData(String, Object)

Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs

Assigns the specified value to the specified application domain property.

public:
 void SetData(System::String ^ name, System::Object ^ data);
public:
 virtual void SetData(System::String ^ name, System::Object ^ data);
public void SetData (string name, object? data);
public void SetData (string name, object data);
[System.Security.SecurityCritical]
public void SetData (string name, object data);
member this.SetData : string * obj -> unit
abstract member SetData : string * obj -> unit
override this.SetData : string * obj -> unit
[<System.Security.SecurityCritical>]
abstract member SetData : string * obj -> unit
override this.SetData : string * obj -> unit
Public Sub SetData (name As String, data As Object)

Parameters

name
String

The name of a user-defined application domain property to create or change.

data
Object

The value of the property.

Implements

Attributes

Exceptions

The operation is attempted on an unloaded application domain.

Examples

The following example demonstrates how to use the SetData(String, Object) method to create a new value pair. The example then uses the GetData method to retrieve the value, and displays it 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 insert an entry, or modify the value of an entry in an internal cache of name-data pairs that describe properties of this instance of AppDomain.

The cache automatically contains predefined system entries that are inserted when the application domain is created. You cannot insert or modify system entries with this method. A method call that attempts to modify a system entry has no effect; the method does not throw an exception. You can inspect the values of system entries with the GetData method, or the equivalent AppDomainSetup properties described in GetData.

You can call this method to set the value of the default timeout interval for evaluating regular expression patterns by supply "REGEX_DEFAULT_MATCH_TIMEOUT" as the value of the name argument and a TimeSpan value that represents the timeout interval as the value of the data argument. You can also insert or modify your own user defined name-data pairs with this method and inspect their values with the GetData method.

See also

Applies to

SetData(String, Object, IPermission)

Assigns the specified value to the specified application domain property, with a specified permission to demand of the caller when the property is retrieved.

public:
 void SetData(System::String ^ name, System::Object ^ data, System::Security::IPermission ^ permission);
public void SetData (string name, object data, System.Security.IPermission permission);
[System.Security.SecurityCritical]
public void SetData (string name, object data, System.Security.IPermission permission);
member this.SetData : string * obj * System.Security.IPermission -> unit
[<System.Security.SecurityCritical>]
member this.SetData : string * obj * System.Security.IPermission -> unit
Public Sub SetData (name As String, data As Object, permission As IPermission)

Parameters

name
String

The name of a user-defined application domain property to create or change.

data
Object

The value of the property.

permission
IPermission

The permission to demand of the caller when the property is retrieved.

Attributes

Exceptions

name is null.

name specifies a system-defined property string and permission is not null.

Remarks

Use this method to insert or modify your own user-defined entries in an internal cache of name/data pairs that describe properties of the application domain. When you insert an entry, you can specify a permission demand to enforce when the entry is retrieved.In addition, you can call this method to set the value of the default timeout interval for evaluating regular expression patterns by supply "REGEX_DEFAULT_MATCH_TIMEOUT" as the value of the name argument and a TimeSpan value that represents the timeout interval as the value of the data argument.

You cannot use this method to assign a security demand to a system-defined property string.

The cache automatically contains predefined system entries that are inserted when the application domain is created. You cannot insert or modify system entries with this method. A method call that attempts to modify a system entry has no effect; the method does not throw an exception. You can inspect the values of system entries with the GetData method or the equivalent AppDomainSetup properties described in the Remarks section for the GetData method.

Applies to