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.

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

Syntax

<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Interface)> _
Public NotInheritable Class DataClientObjectAttribute _
    Inherits Attribute

Dim instance As DataClientObjectAttribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface)]
public sealed class DataClientObjectAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Interface)]
public ref class DataClientObjectAttribute sealed : public Attribute
public final class DataClientObjectAttribute 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 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.");
        }
    }
}

Inheritance Hierarchy

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

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

DataClientObjectAttribute Members

Microsoft.VisualStudio.Data.Core Namespace