DekGenius.com
[ Team LiB ] Previous Section Next Section

ActivatorCF 1.0

System (mscorlib.dll)sealed class

This class is used to activate objects; that is, it either creates an object or obtains a handle to an existing object. This class is generally used in a variety of specialized conditions. For example, Activator can create an object within another AppDomain and hold a handle to that object. This effectively gives a multidomain container application (such as ASP.NET) the ability to reach into another AppDomain to perform tasks within that domain (such as closing down the AppDomain in the event of a user request to shut down the application server).

Activator's methods come in two distinct flavors: CreateInstance( ) and CreateInstanceFrom( ). These create new objects when given particular criteria (such as the type to create and the assembly from which to create it). The GetObject( ) method uses published System.Runtime.Remoting.RemotingConfiguration data to locate another object and obtain a handle to it (usually in preparation for some remote-object method invocations).

All of the methods in Activator return a System.Runtime.Remoting.ObjectHandle, not the actual object itself; this object is actually a proxy to the created/remote object. As such, programmers must call Unwrap( ) on the returned ObjectHandle to use the object. (Note that an explicit downcast is required, since the return value is declared to be a generic object.)

Figure 26-5. Value types in the System namespace
figs/csn2_2605.gif
public sealed class Activator {
// Public Static Methods
   public static ObjectHandle CreateComInstanceFrom(string assemblyName, string typeName);
   public static ObjectHandle CreateComInstanceFrom(string assemblyName, string typeName, 
        byte[ ] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm);
   public static object CreateInstance(Type type);
   public static object CreateInstance(Type type, System.Reflection.BindingFlags bindingAttr, 
        System.Reflection.Binder binder, object[ ] args, System.Globalization.CultureInfo culture);
   public static object CreateInstance(Type type, System.Reflection.BindingFlags bindingAttr,  
        System.Reflection.Binder binder, object[ ] args, System.Globalization.CultureInfo culture, 
        object[ ] activationAttributes);
   public static object CreateInstance(Type type, bool nonPublic);
   public static object CreateInstance(Type type, object[ ] args);
   public static object CreateInstance(Type type, object[ ] args, object[ ] activationAttributes);
   public static ObjectHandle CreateInstance(string assemblyName, string typeName);
   public static ObjectHandle CreateInstance(string assemblyName, string typeName, bool ignoreCase, 
        System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[ ] args, 
        System.Globalization.CultureInfo culture, object[ ] activationAttributes, 
        System.Security.Policy.Evidence securityInfo);
   public static ObjectHandle CreateInstance(string assemblyName, string typeName, object[ ] activationAttributes);
   public static ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName);
   public static ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, 
        System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[ ] args, 
        System.Globalization.CultureInfo culture, object[ ] activationAttributes, 
        System.Security.Policy.Evidence securityInfo);
   public static ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName, 
   object[ ] activationAttributes);
   public static object GetObject(Type type, string url);
   public static object GetObject(Type type, string url, object state);
}
    [ Team LiB ] Previous Section Next Section