Compartir a través de


DataDefaultObjectAttribute Class

Specifies that a DDEX support entity has a default implementation that should be returned when a provider does not supply an implementation.

Inheritance Hierarchy

System.Object
  System.Attribute
    Microsoft.VisualStudio.Data.Core.DataDefaultObjectAttribute

Namespace:  Microsoft.VisualStudio.Data.Core
Assembly:  Microsoft.VisualStudio.Data.Core (in Microsoft.VisualStudio.Data.Core.dll)

Syntax

'Declaration
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Interface)> _
Public NotInheritable Class DataDefaultObjectAttribute _
    Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface)]
public sealed class DataDefaultObjectAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Interface)]
public ref class DataDefaultObjectAttribute sealed : public Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface)>]
type DataDefaultObjectAttribute =  
    class 
        inherit Attribute 
    end
public final class DataDefaultObjectAttribute extends Attribute

The DataDefaultObjectAttribute type exposes the following members.

Constructors

  Name Description
Public method DataDefaultObjectAttribute Initializes a new instance of the DataDefaultObjectAttribute class, using the specified class ID.

Top

Properties

  Name Description
Public property ClassId Gets the class ID that identifies the default object class type.
Public property TypeId When implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)

Top

Methods

  Name Description
Public method Equals Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Public method GetHashCode Returns the hash code for this instance. (Inherited from Attribute.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method IsDefaultAttribute When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Public method Match When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate method _Attribute.GetIDsOfNames Maps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.GetTypeInfo Retrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.GetTypeInfoCount Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.Invoke Provides access to properties and methods exposed by an object. (Inherited from Attribute.)

Top

Remarks

When a DDEX client calls the DDEX runtime to create an instance of a DDEX support entity for a particular provider, the provider is queried to determine whether it supports the entity, and, if it does, an instance is created and returned. If the provider does not support the entity, the call by default either throws an exception or returns nulla null reference (Nothing in Visual Basic), depending on the code path. However, in some cases, the owners of the DDEX support entity may have a reasonable default implementation that they want to supply to clients when a DDEX provider does not supply its own implementation, thus avoiding the error condition.

One example of this in practice is the IVsDataConnectionUIConnector support entity. This support entity contains a single method that is called to open a data connection from a UI context, like a data connection dialog box. The typical use of this support entity is to add additional behavior, such as checking for the existence of the data connection target and prompting to create a new data store if it is not found. However, a reasonable default is to simply open the connection normally and do nothing special. If this default implementation is supplied, client code is simplified because it no longer needs to separately handle the cases in which the provider does or does not implement the support entity, nor does it need to provide with its own fallback, default implementation.

DDEX support entities that have a reasonable default implementation should include this attribute on the type representing the support entity. The attribute must include a value for the ClassId property, and the value must be a valid GUID representing a class ID registered in the Visual Studio environment. Finally, the class identified by the class ID must be a managed class that implements the IVsDataDefaultObject interface. When a client requests the creation of an instance of the class with the specified ID, the DDEX runtime will create this instance if no provider implementation is available. The default implementation is then passed back to the client.

The DataDefaultObjectAttribute attribute is primarily of interest to DDEX platform extenders, that is, those creating additional DDEX services and support entities.

Examples

The following code shows the definition of the IVsDataConnectionUIConnector support entity that declares a default object attribute. The definition is followed by the implementation of this default object.

using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Data.Core;
using Microsoft.VisualStudio.Data.Services;

[DataDefaultObject("C58E1B8D-9723-40c8-8B11-9DDAF0B393BA")]
public interface IVsDataConnectionUIConnector
{
    void Connect(IVsDataConnection connection);
}

[Guid("C58E1B8D-9723-40c8-8B11-9DDAF0B393BA")]
internal class DefaultConnectionUIConnector
    : IVsDataConnectionUIConnector,
      IVsDataDefaultObject
{
    public void Connect(IVsDataConnection connection)
    {
        if (connection == null)
        {
            throw new ArgumentNullException("connection");
        }
        connection.Open();
    }
}

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.Data.Core Namespace