AppDomain.SetData AppDomain.SetData AppDomain.SetData AppDomain.SetData Method

定义

为应用程序域属性分配值。Assigns a value to an application domain property.

重载

SetData(String, Object) SetData(String, Object) SetData(String, Object) SetData(String, Object)

为指定的应用程序域属性分配指定值。Assigns the specified value to the specified application domain property.

SetData(String, Object, IPermission) SetData(String, Object, IPermission) SetData(String, Object, IPermission) 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) SetData(String, Object) SetData(String, Object) SetData(String, Object)

为指定的应用程序域属性分配指定值。Assigns the specified value to the specified application domain property.

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

参数

name
String String String String

要创建或更改的用户定义应用程序域属性的名称。The name of a user-defined application domain property to create or change.

data
Object Object Object Object

该属性的值。The value of the property.

实现

异常

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

示例

下面的示例演示如何使用SetData(String, Object)方法创建新的值对。The following example demonstrates how to use the SetData(String, Object) method to create a new value pair. 然后, 该示例使用GetData方法检索该值, 并将其显示在控制台中。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
 */

Imports System
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 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. 可以用GetData方法或中GetData描述的等效AppDomainSetup属性检查系统项的值。You can inspect the values of system entries with the GetData method, or the equivalent AppDomainSetup properties described in GetData.

您可以通过将 "REGEX_DEFAULT_MATCH_TIMEOUT" 作为name参数的值TimeSpan和表示超时值的值, 来设置默认超时间隔的值, 以便通过提供 "" 来计算正则表达式模式间隔作为data参数的值。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. 还可以通过此方法插入或修改自己的用户定义的名称数据对, 并通过GetData方法检查其值。You can also insert or modify your own user defined name-data pairs with this method and inspect their values with the GetData method.

安全性

SecurityCriticalAttribute
需要对直接调用方的完全信任。requires full trust for the immediate caller. 部分受信任的或透明的代码不能使用此成员。This member cannot be used by partially trusted or transparent code.

另请参阅

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

参数

name
String String String String

要创建或更改的用户定义应用程序域属性的名称。The name of a user-defined application domain property to create or change.

data
Object Object Object Object

该属性的值。The value of the property.

permission
IPermission IPermission IPermission IPermission

检索属性时调用方需要具有的权限。The permission to demand of the caller when the property is retrieved.

异常

name 指定系统定义的属性字符串,并且 permission 不为 nullname specifies a system-defined property string and permission is not null.

注解

使用此方法可在描述应用程序域属性的名称/数据对的内部缓存中插入或修改自己的用户定义条目。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. 插入项时, 可以指定在检索项时要强制执行的权限请求。此外, 还可以调用此方法, 通过将 "REGEX_DEFAULT_MATCH_TIMEOUT" 作为name参数的值TimeSpan和表示参数值的值, 来设置默认超时间隔的值, 以计算正则表达式模式超时间隔作为data参数的值。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. 可以通过GetData方法或GetData方法的 "备注" 部分中所述的AppDomainSetup等效属性来检查系统项的值。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.

安全性

SecurityCriticalAttribute
需要对直接调用方的完全信任。requires full trust for the immediate caller. 部分受信任的或透明的代码不能使用此成员。This member cannot be used by partially trusted or transparent code.

适用于