Compartilhar via


IVsDataSourceSpecializer.GetAssembly Method

Resolves a provider-specific assembly string to its corresponding Assembly 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 GetAssembly ( _
    source As Guid, _
    assemblyString As String _
) As Assembly
Assembly GetAssembly(
    Guid source,
    string assemblyString
)
Assembly^ GetAssembly(
    Guid source, 
    String^ assemblyString
)
abstract GetAssembly : 
        source:Guid * 
        assemblyString:string -> Assembly
function GetAssembly(
    source : Guid, 
    assemblyString : String
) : Assembly

Parameters

  • source
    Type: System.Guid

    A DDEX data source identifier.

  • assemblyString
    Type: System.String

    A provider-specific assembly string.

Return Value

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

Exceptions

Exception Condition
ArgumentNullException

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

Remarks

A provider implements this method when there are assembly names specified as strings in formats such as a data support XML file, and these assembly names cannot be automatically resolved (or would be resolved incorrectly) by the CLR’s Load method. One use of this method would be to expand an incomplete assembly declaration. (For example, if the string is "MyAssembly" it might get expanded to "MyAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=1234567890ABCDEF" before the CLR resolves it.)

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

Examples

The following code demonstrates how to implement this method to return different assemblies 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 System.Reflection;
using Microsoft.VisualStudio.Data.Core;
using Microsoft.VisualStudio.Data.Framework;

public class MySourceSpecializer4 : DataSourceSpecializer
{
    private static readonly Guid s_dataSource1 =
        new Guid("EB5246D3-277C-4277-910F-111CB9EAD253");
    private static readonly Guid s_dataSource2 =
        new Guid("1EC8B196-7155-4d5a-BBDC-0CC47D631E52");

    public override Assembly GetAssembly(Guid source, string assemblyString)
    {
        if (source == s_dataSource1)
        {
            return Assembly.Load("AssemblyForDataSource1");
        }
        else if (source == s_dataSource2)
        {
            return Assembly.Load("AssemblyForDataSource2");
        }
        else
        {
            return base.GetAssembly(source, assemblyString);
        }
    }
}

.NET Framework Security

See Also

Reference

IVsDataSourceSpecializer Interface

Microsoft.VisualStudio.Data.Core Namespace