GlobalObject Class
Provides the base class for types whose instances are accessible for each project.
Inheritance Hierarchy
System.Object
System.MarshalByRefObject
Microsoft.VisualStudio.Shell.Design.GlobalType
Microsoft.VisualStudio.Shell.Design.GlobalObject
Namespace: Microsoft.VisualStudio.Shell.Design
Assembly: Microsoft.VisualStudio.Shell.Design (in Microsoft.VisualStudio.Shell.Design.dll)
Syntax
'宣告
Public MustInherit Class GlobalObject _
Inherits GlobalType
public abstract class GlobalObject : GlobalType
The GlobalObject type exposes the following members.
Constructors
Name | Description | |
---|---|---|
GlobalObject | Initializes a new instance of the GlobalObject class. |
Top
Properties
Name | Description | |
---|---|---|
Instance | Gets an on-demand created instance of the global object. | |
Name | Gets the recommended name of the global object. | |
ObjectType | Gets the checked type of the GlobalType. (Inherited from GlobalType.) |
Top
Methods
Name | Description | |
---|---|---|
ClearInstance | Clears the Instance property. | |
ClearObjectType | Clears the ObjectType property. (Inherited from GlobalType.) | |
CreateInstance | Creates a cached instance of the global object. | |
CreateObjRef | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.) | |
Equals | Checks if the specified object is equal to the current global object. (Overrides GlobalType.Equals(Object).) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Returns the hash code for the current global object. (Overrides GlobalType.GetHashCode().) | |
GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.) | |
GetObjectType | Returns the type of this global type. (Inherited from GlobalType.) | |
GetSerializer | Returns the checked serializer of the specified type for the global object. | |
GetSerializerCore | Returns a serializer of the specified type for the global object. | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.) | |
MemberwiseClone() | Creates a shallow copy of the current Object. (Inherited from Object.) | |
MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.) | |
OnChanged | Raises the Changed event. (Inherited from GlobalType.) | |
OnChanging | Raises the Changing event. (Inherited from GlobalType.) | |
OnCreated | Raises the Created event. | |
OnRemoved | Raises the Removed event. (Inherited from GlobalType.) | |
OnRemoving | Raises the Removing event. (Inherited from GlobalType.) | |
PerformChange | Reinitializes the global object and notifies users to changes to its state or shape. (Overrides GlobalType.PerformChange().) | |
PerformRemove | Clears the global object and notifies users of its removal. (Overrides GlobalType.PerformRemove().) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Top
Events
Name | Description | |
---|---|---|
Changed | Occurs after the current global type is modified. (Inherited from GlobalType.) | |
Changing | Occurs before the current global type is modified. (Inherited from GlobalType.) | |
Created | Occurs when an instance of the global object is created. | |
Removed | Occurs after the current global type is removed from use. (Inherited from GlobalType.) | |
Removing | Occurs before the current global type is removed from use. (Inherited from GlobalType.) |
Top
Remarks
A global object is an object that is accessible over an entire project, rather than just within a single application or a single form. For example, project-wide resource files provided in a Windows Forms application are global objects. Global objects have the following characteristics:
They are global to a project and are therefore single-instanced.
They are accessed by means of a static method or property on a class.
They are commonly custom types that are automatically generated by the project system.
They often change as a result of actions in other files within the project.
They can be marshaled from the default domain across other application domains because the GlobalObject class is derived from System.MarshalByRefObject. Marshaling requires that the global object instance be serializable.
While you perceive global objects as global, and this is also how they behave at runtime, at design time they are actually instanced for each designer. This enables the designers to maintain their own copies and remain isolated. The GlobalObjectService interacts with instances of GlobalObject in order to create these global object instances for each designer.
Global objects are not created directly; rather, a call to the GetGlobalObjects method of the GlobalObjectService class initiates a process that creates the desired global object instance.
GlobalObject also supports the creation of global types. A global type is a standard instanced object, but the type for this object comes from a project in the solution or from generated code. For more information about global types, see the base class GlobalType.
In the first version of the .NET Framework, types and instances were exposed through the existing project references system. Because this system uses real, compiled types it suffered from slower performance, duplicated data types, and the need to restart the designer environment when types were changed. Global types and virtual types were introduced in the second version of the Managed Package Framework to solve these problems. A virtual type enables the dynamic creation of a type and instances of that type based on an existing base class. Virtual types mimic ordinary compiled types when examined by the reflection application programming interface (API), but do not have a true class implementation. For more information about virtual types, see the VirtualTypeBuilder class.
Examples
The following code example shows some global objects.
DataSet cust = Customers.DefaultInstance;
String error = MyAppResources.ErrorString;
Bitmap logo = MyAppResources.ProductLogo;
The following code example shows some global types.
DataSet cust = new CustomerDataSet();
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Reference
Microsoft.VisualStudio.Shell.Design Namespace