|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Check Interface Implementation of a TypeHello folks,
I'm dynamically loading assembly by looping through types in the assembly. But I want to load the types that implements a interface. So the issue I'm having is whether I can check a type implements an interface. Of course, I could load the type by invoking CreateInstance of the assembly and do TryCast, but I want to know whether the type implements the interface before I load the type. >So the issue I'm having is whether I can check a type implements an Sure, check out the Type.IsAssignableFrom method.>interface. Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Hello,
Hello, thank you very much for your reply. I tried IsAssignableFrom myself, but it always returns false. I have an Interface "ITest". And my "Customer" class implements "ITest". Here is what I did... Sub Main() Dim cust As New Customer(1, "MyFirstName", "MyLastName") Console.WriteLine(cust.GetType().IsAssignableFrom(GetType(ITest))) Console.Read() End Sub I would expect IsAssignableFrom() function to return True, but it return false. Am I doing something wrong? Hayato Iriumi wrote:
<snip> > I tried IsAssignableFrom myself, but it always returns false. I have an <snip>> Interface "ITest". And my "Customer" class implements "ITest". Here is > what I did... > Console.WriteLine(cust.GetType().IsAssignableFrom(GetType(ITest))) <snip>> I would expect IsAssignableFrom() function to return True, but it According to the docs, it seems you should be dowing:> return false. Am I doing something wrong? Console.WriteLine(GetType(ITest).IsAssignableFrom(cust.GetType())) because A.IsAssignableFrom(B) will be true if B is a type that implements A (and not the other way around)... Regards, Branco Yes, you're right about that. I tested it works now. Thank you very
much for your help!
Option Strict On
disabling controls by checking off a radio button when the form loads Can't close EXCEL from my VB.NET application Currently logged in user's email SENDMail Get a simple handler Invoking CTRL+C,X,V programatically Double-Buffering in VB2005? save string var to html file without losing format Clearing data from a DataGrid |
|||||||||||||||||||||||