DataDefaultObjectAttribute Class

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

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
'Usage
Dim instance As DataDefaultObjectAttribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface)]
public sealed class DataDefaultObjectAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Interface)]
public ref class DataDefaultObjectAttribute sealed : public Attribute
public final class DataDefaultObjectAttribute extends Attribute

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();
    }
}

Inheritance Hierarchy

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

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

DataDefaultObjectAttribute Members

Microsoft.VisualStudio.Data.Core Namespace