Share via


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

'Declaration
Public MustInherit Class GlobalObject _
    Inherits GlobalType
public abstract class GlobalObject : GlobalType
public ref class GlobalObject abstract : public GlobalType
[<AbstractClass>]
type GlobalObject =  
    class
        inherit GlobalType
    end
public abstract class GlobalObject extends GlobalType

The GlobalObject type exposes the following members.

Constructors

  Name Description
Protected method GlobalObject Initializes a new instance of the GlobalObject class.

Top

Properties

  Name Description
Public property Instance Gets an on-demand created instance of the global object.
Public property Name Gets the recommended name of the global object.
Public property ObjectType Gets the checked type of the GlobalType. (Inherited from GlobalType.)

Top

Methods

  Name Description
Protected method ClearInstance Clears the Instance property.
Protected method ClearObjectType Clears the ObjectType property. (Inherited from GlobalType.)
Protected method CreateInstance Creates a cached instance of the global object.
Public method 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.)
Public method Equals Checks if the specified object is equal to the current global object. (Overrides GlobalType.Equals(Object).)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Returns the hash code for the current global object. (Overrides GlobalType.GetHashCode().)
Public method GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method GetObjectType Returns the type of this global type. (Inherited from GlobalType.)
Public method GetSerializer Returns the checked serializer of the specified type for the global object.
Public method GetSerializerCore Returns a serializer of the specified type for the global object.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected method OnChanged Raises the Changed event. (Inherited from GlobalType.)
Protected method OnChanging Raises the Changing event. (Inherited from GlobalType.)
Protected method OnCreated Raises the Created event.
Protected method OnRemoved Raises the Removed event. (Inherited from GlobalType.)
Protected method OnRemoving Raises the Removing event. (Inherited from GlobalType.)
Protected method PerformChange Reinitializes the global object and notifies users to changes to its state or shape. (Overrides GlobalType.PerformChange().)
Protected method PerformRemove Clears the global object and notifies users of its removal. (Overrides GlobalType.PerformRemove().)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Events

  Name Description
Public event Changed Occurs after the current global type is modified. (Inherited from GlobalType.)
Public event Changing Occurs before the current global type is modified. (Inherited from GlobalType.)
Public event Created Occurs when an instance of the global object is created.
Public event Removed Occurs after the current global type is removed from use. (Inherited from GlobalType.)
Public event 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

GlobalObjectService

GlobalObjectProvider

GlobalObjectProviderFactory

ProvideGlobalObjectProviderAttribute

VirtualTypeBuilder