Freigeben über


IVsDataSourceSpecializer.GetType Method

Resolves a provider-specific type name to its corresponding Type representation, for a specific DDEX data source.

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

Syntax

'Declaration
Function GetType ( _
    source As Guid, _
    typeName As String _
) As Type
Type GetType(
    Guid source,
    string typeName
)
Type^ GetType(
    Guid source, 
    String^ typeName
)
abstract GetType : 
        source:Guid * 
        typeName:string -> Type 
function GetType(
    source : Guid, 
    typeName : String
) : Type

Parameters

  • source
    Type: System.Guid
    A DDEX data source identifier.

Return Value

Type: System.Type
An Type object representing the type resolved from the specified type name, for the specified DDEX data source, if found; otherwise, nulla null reference (Nothing in Visual Basic).

Exceptions

Exception Condition
ArgumentNullException

The typeName parameter is nulla null reference (Nothing in Visual Basic).

Remarks

A provider implements this method when there are type names specified as strings in formats such as a data support XML file, and these type names cannot be automatically resolved (or would be resolved incorrectly) by the CLR’s GetType method. One use of this method would be to expand an unspecified namespace. (For example, if the string is "MyType" it might get expanded to "Company.Product.MyType" before the CLR resolves it.)

This method is provided to shorten a provider’s specification of type names, which can help reduce duplication of items, like a common namespace, throughout the code base. The data source specialization supplied by this method further enables using common type names to reference potentially different types when different DDEX data sources are targeted by the client.

Examples

The following code demonstrates implementing this method to prepend different namespaces to all type names, depending on the DDEX data source. The example inherits from the framework DataSourceSpecializer class, which provides a default implementation of the other methods on the interface.

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

public class MySourceSpecializer5 : DataSourceSpecializer
{
    private static readonly Guid s_dataSource1 =
        new Guid("EB5246D3-277C-4277-910F-111CB9EAD253");

    public override Type GetType(Guid source, string typeName)
    {
        if (source == s_dataSource1)
        {
            typeName = "Company.DdexProvider.Source1." + typeName;
        }
        else
        {
            typeName = "Company.DdexProvider." + typeName;
        }
        return GetType().Assembly.GetType(typeName);
    }
}

.NET Framework Security

See Also

Reference

IVsDataSourceSpecializer Interface

Microsoft.VisualStudio.Data.Core Namespace