UNKNOWN //************************************** // Name: Late Binding to .NET objects // Description:This example shows how to do late binding in .NET. The provided function LoadClass() is similar to CreateObject() function in that you can reference and use external libraries at run time. // By: Igor Krupitsky // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //This code is copyrighted and has limited warranties. //Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.5609/lngWId.10/qx/vb/scripts/ShowCode.htm //for details. //************************************** // 'Example of use Dim oViewer As Object = LoadClass("CrystalDecisions.Web", "CrystalDecisions.Web.CrystalReportViewer") Function LoadClass(ByVal sAssemblyName As String, ByVal sClassName As String) As Object 'Get Assembly Dim oAssembly As Reflection.Assembly Try oAssembly = Reflection.[Assembly].LoadWithPartialName(sAssemblyName) Catch Throw New ArgumentException("Can't load assembly " + sAssemblyName) End Try Dim iVersion As Integer = oAssembly.GetName().Version.Major 'Get Class Dim oType As Type = oAssembly.GetType(sClassName, False, False) If oType Is Nothing Then Throw New ArgumentException("Can't load type " + sClassName) End If 'Instantiate Dim oTypes(-1) As Type Dim oInfo As Reflection.ConstructorInfo = oType.GetConstructor(oTypes) Dim oRetObj As Object = oInfo.Invoke(Nothing) If oRetObj Is Nothing Then Throw New ArgumentException("Can't instantiate type " + sClassName) End If Return oRetObj End Function