Partager via


DataClientObjectAttribute Class

Specifies that instances of a DDEX support entity should not be directly returned to clients. Instead, they should be returned through a client wrapper object that interacts with the underlying provider object.

Inheritance Hierarchy

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

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 DataClientObjectAttribute _
    Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface)]
public sealed class DataClientObjectAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Interface)]
public ref class DataClientObjectAttribute sealed : public Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface)>]
type DataClientObjectAttribute =  
    class 
        inherit Attribute 
    end
public final class DataClientObjectAttribute extends Attribute

The DataClientObjectAttribute type exposes the following members.

Constructors

  Name Description
Public method DataClientObjectAttribute Initializes a new instance of the DataClientObjectAttribute class, specifying the class ID.

Top

Properties

  Name Description
Public property ClassId Gets the class ID that identifies the client 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 object is typically created and returned directly to the client. In this case, the client has a direct handle to the provider’s implementation. In some cases, the owner of the definition of the DDEX support entity may want to define additional or modified behavior for the support entity when it interacts with the client. This might help to meet client expectations without adding extra work for the provider writer.

The most common example of this requirement comes in the form of DDEX connection services, such as the IVsDataCommand support entity. One function of IVsDataConnection, the DDEX connection object, is to minimize the overhead required on the client side to ensure that the connection is currently open and not being used by another client, but at the same time eliminate concerns about these issues on the provider side. Therefore a given connection service may have a client object associated with it that performs extra logic ensuring that the connection is open and correctly shared among multiple clients. This implementation wraps the underlying provider object and is automatically supplied to the client by the DDEX runtime.

DDEX support entities for which you intend to have the DDEX runtime return a client wrapper object upon creation of the provider’s support entity should include this attribute on the type that represents the support entity. The attribute must include a value for the ClassId property, and the value must be a valid GUID that represents 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 IVsDataClientObject<T> interface. When requested by a client, the DDEX runtime will first create an instance of the underlying provider object. It will then create an instance of the class that has the specified class ID. Next, it will initialize the client object by calling the Initialize method with the underlying provider object. The client object is then passed back to the client.

The DataClientObjectAttribute attribute is primarily useful to DDEX platform extenders, that is, those creating additional DDEX services and support entities.

Examples

The following code shows the definition of a fictitious support entity that declares a client object attribute. The definition is followed by the implementation of this client object, which adds simple logging of the calls to the support entity.

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

namespace DataClientObjectAttrib
{
    [DataClientObject("1520C77F-09AF-40b4-B1FE-53C30A177C59")]
    public interface IVsDataSupportEntity
    {
        void DoSomething();
    }

    [Guid("1520C77F-09AF-40b4-B1FE-53C30A177C59")]
    internal class ClientSupportEntity : IVsDataSupportEntity,
        IVsDataClientObject<IVsDataSupportEntity>
    {
        private IVsDataSupportEntity _providerObj;

        public void Initialize(IVsDataSupportEntity providerObj)
        {
            if (providerObj == null)
            {
                throw new ArgumentNullException("providerObj");
            }
            _providerObj = providerObj;
        }

        public void DoSomething()
        {
            Trace.WriteLine("DoSomething started.");
            _providerObj.DoSomething();
            Trace.WriteLine("DoSomething finished.");
        }
    }
}

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