rbulph Posted November 10, 2005 Posted November 10, 2005 In VB6 I used the TypeLib Information dll (tlbinf32.dll) to find out about the classes contained in a plug-in Class Library. Is that still the best way to do it in .net? Quote
Administrators PlausiblyDamp Posted November 10, 2005 Administrators Posted November 10, 2005 If the dll is written in .Net then you can use reflection (System.Reflection is the namespace) to find out about an assemblies contents. http://www.xtremedotnettalk.com/showthread.php?t=77697 has a good example of how to use reflection. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
rbulph Posted November 10, 2005 Author Posted November 10, 2005 Thanks. How could I store a description with each class and use Reflection to extract this? Quote
bri189a Posted November 10, 2005 Posted November 10, 2005 You could find out about the assembly version, possibly the culture, and other things that are assembly specific. You could also findout the types within the assembly, the methods, properties, and attributes of each type in the assembly. If a type has a field named description, you could find that out- but I don't think anybody would do that. Quote
Leaders snarfblam Posted November 10, 2005 Leaders Posted November 10, 2005 If you are the person writing the class then you could supply a System.ComponentModel.DescriptionAttribute for a class and extract that attribute from the DLL with reflection. [vB] 'Supply a description <System.ComponentModel.Description("A class that I made.")> _ Public Class My_Class 'This function will load and display the description Public Shared Sub LoadAndDisplayAttribute Dim ClassType As System.Type = GetType(My_Class) 'Get a list of description attributes Dim Attributes As Object() = ClassType.GetCustomAttributes( _ GetType(System.ComponentModel.DescriptionAttribute), False) If Attributes.Length > 0 Then 'Only one description attribute may be applied to a class definition, 'so we will assume that our description is Attributes(0) MessageBox.Show(CType(Attributes(0), System.ComponentModel.DescriptionAttribute).Description) End If End Sub End Class [/code] Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.