Share via


IVsDataSource.DisplayName Property

Gets the display name of the DDEX data source.

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

Syntax

'Declaration
ReadOnly Property DisplayName As String
string DisplayName { get; }
property String^ DisplayName {
    String^ get ();
}
abstract DisplayName : string with get
function get DisplayName () : String

Property Value

Type: System.String
The display name of the DDEX data source.

Remarks

The display name of a DDEX data source is a localized string that can be displayed by DDEX clients to end users. One example of this occurs in the data connection Choose Data Source dialog box, where a DDEX data source and provider are selected by the user.

This property determines the display name by calling the GetProperty method, passing in the default supporting provider (if there is one) and the parameter DisplayName, to retrieve a string resource ID. If this fails, the property just starts iterating through the supporting providers, querying each for the same property until a non-null value is returned. It then calls the GetString method to retrieve the localized string that is associated with the resource ID. If no resource exists, the value of the IVsDataSource.Name property is returned.

An example value for this property might be "Microsoft SQL Server".

Examples

The following code demonstrates the implementation of the DisplayName property. Since localized strings are provided only by supporting providers, it determines an appropriate supporting provider to use based on the default provider and/or which providers supply values for the DisplayName property. It then resolves this to the actual localized string by using the DDEX provider API.

using System;
using System.Data;
using System.Data.Common;
using Microsoft.VisualStudio.Data.Core;

public class DDEX_IVsDataSourceExample2
{
    public static string GetSourceDisplayName(
        IServiceProvider serviceProvider,
        IVsDataSource dataSource)
    {
        string displayName = null;
        string resourceId = null;
        Guid provider = dataSource.DefaultProvider;
        if (provider != Guid.Empty)
        {
            resourceId = dataSource.GetProperty(provider, "DisplayName") as string;
        }
        if (resourceId == null)
        {
            foreach (Guid providerId in dataSource.GetProviders())
            {
                resourceId = dataSource.GetProperty(
                    providerId, "DisplayName") as string;
                if (resourceId != null)
                {
                    provider = providerId;
                    break;
                }
            }
        }
        if (provider != Guid.Empty && resourceId != null)
        {
            IVsDataProviderManager providerManager = serviceProvider.GetService(
                typeof(IVsDataProviderManager)) as IVsDataProviderManager;
            IVsDataProvider dataProvider = providerManager.Providers[provider];
            displayName = dataProvider.GetString(resourceId);
        }
        return displayName;
    }
}

.NET Framework Security

See Also

Reference

IVsDataSource Interface

Microsoft.VisualStudio.Data.Core Namespace