AppDomain.SetData 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为应用程序域属性分配值。
重载
| SetData(String, Object) | 
						 为指定的应用程序域属性分配指定值。  | 
        	
| SetData(String, Object, IPermission) | 
						 将指定值分配给指定应用程序域属性,检索该属性时要求调用方具有指定权限。  | 
        	
SetData(String, Object)
- Source:
 - AppDomain.cs
 
- Source:
 - AppDomain.cs
 
- Source:
 - AppDomain.cs
 
为指定的应用程序域属性分配指定值。
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)
	参数
- name
 - String
 
要创建或更改的用户定义应用程序域属性的名称。
- data
 - Object
 
该属性的值。
实现
- 属性
 
例外
在卸载的应用程序域上尝试该操作。
示例
以下示例演示如何使用 SetData(String, Object) 方法创建新的值对。 然后,该示例使用 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条目的值。
缓存自动包含创建应用程序域时插入的预定义系统条目。 不能使用此方法插入或修改系统条目。 尝试修改系统条目的方法调用不起作用;方法不会引发异常。 可以使用 方法或中所述GetData的等效AppDomainSetup属性来检查系统条目GetData的值。
可以调用此方法来设置用于计算正则表达式模式的默认超时间隔的值,方法是提供“REGEX_DEFAULT_MATCH_TIMEOUT”作为参数的值 name ,并提供一个 TimeSpan 将超时间隔表示为参数的值 data 。 还可以使用此方法插入或修改自己的用户定义的名称数据对,并使用 方法检查其值 GetData 。
另请参阅
适用于
SetData(String, Object, IPermission)
将指定值分配给指定应用程序域属性,检索该属性时要求调用方具有指定权限。
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)
	参数
- name
 - String
 
要创建或更改的用户定义应用程序域属性的名称。
- data
 - Object
 
该属性的值。
- permission
 - IPermission
 
检索属性时调用方需要具有的权限。
- 属性
 
例外
              name 为 null。
              name 指定系统定义的属性字符串,并且 permission 不为 null。
注解
使用此方法在描述应用程序域属性的名称/数据对的内部缓存中插入或修改自己的用户定义的条目。 插入条目时,可以指定在检索条目时强制实施的权限要求。此外,可以通过提供“REGEX_DEFAULT_MATCH_TIMEOUT”作为参数的值和TimeSpan表示超时间隔的值作为参数的值name来设置用于计算正则表达式模式的默认超时间隔的值data。
不能使用此方法将安全需求分配给系统定义的属性字符串。
缓存自动包含创建应用程序域时插入的预定义系统条目。 不能使用此方法插入或修改系统条目。 尝试修改系统条目的方法调用不起作用;方法不会引发异常。 可以使用 方法或方法的备注部分GetData所述的等效AppDomainSetup属性检查系统条目GetData的值。