473,721 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reflection question

Hello - I am wanting to print out a "Yes" next to classes that
implement "Interface0 1", otherwise a "No". Here is my code. It crashes
with a null reference exception and I am not sure why. Ideas?
Thank you for you help.
Tony
Imports System.Reflecti on

Public Class Form1
Inherits System.Windows. Forms.Form

''Windows Form Designer generated code

Interface Interface01
End Interface

MustInherit Class Abstract01
End Class

Class Class01
Implements Interface01
End Class

Class Class02
End Class

Class Class03
Inherits Class01
End Class

Class ClassA2
Inherits Abstract01
End Class

Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
Dim asmbly As [Assembly] = [Assembly].GetExecutingAs sembly()
Dim asmblyType As Type
For Each asmblyType In asmbly.GetTypes
If asmblyType.Base Type.Equals(Get Type(Interface0 1)) Then
Debug.Write("Ye s: ")
Else : Debug.Write("No : ")
End If
Debug.WriteLine (asmblyType.Ful lName)
Next
End Sub
End Class
Nov 20 '05
12 2368
Hi Tom,

Maybe I should have said 'executable' or 'application' then, for it is the
collection of Assemblies that make up a program that I'm thinking about.

Regards,
Fergus
Nov 20 '05 #11
Hi Tony,

Lol, actually this is out of my area but I was asking on your behalf as I
knew that this was what you were after. :-)

Having just seen Tom's answer, I wanted to get in there quick and steer
him right. I do this quite often (in the group generally - not with Tom). This
time I chose to do it as a question but my arrow fell short. :-((

I think the problem with GetAssemblies is that it will get those that have
been loaded so far, not the entire list. I would hope that there's a way to
get them all. It makes good sense that the information is there somewhere but
it may be distributed rather than centralised.

What do you reckon Tom? ;-)

Regards,
Fergus
Nov 20 '05 #12

"Fergus Cooney" <fi******@tesco .net> wrote in message
news:ur******** *****@TK2MSFTNG P11.phx.gbl...
Hi Tony,

Lol, actually this is out of my area but I was asking on your behalf as I knew that this was what you were after. :-)

Having just seen Tom's answer, I wanted to get in there quick and steer him right. I do this quite often (in the group generally - not with Tom). This time I chose to do it as a question but my arrow fell short. :-((

I think the problem with GetAssemblies is that it will get those that have been loaded so far, not the entire list. I would hope that there's a way to get them all. It makes good sense that the information is there somewhere but it may be distributed rather than centralised.

Well, might as well through my hat into the ring as I've recently worked
with reflection.

Now, regarding the first question of a collection of the assemblies that
make up an "applicatio n" being stored somewhere, Tom's answer is dead on.
Or at least I think the best way to accomplish the task with the way most
people program. That is, you have a primary executable which may call a
series of libraries held in other assemblies. These are all usually loaded
at executation of the main assembly. The only time its not, is if your
doing something like modular coding where you use reflection to dynmiaclly
load assemblies at different times in the programs lifecycle.

If that is true, you could always recusivly push through each reference of
the primary assembly. Use GetReferencedAs semblies and
GetSatelliteAss emblies (if needed). Which both return collections of
assembly references. So, unless you are dynamically invoking methods your
program knows absolutly nothing about from assemblies it knows absolutly
nothing about, (I mean no interfaces either, kinda like a really really
really dynamic unit tester... hmmmmm.. interesting idea). there should be
no need other than those two methods. And as said, going through them
recursivly will tell you every single assembly you want to know about.

Hope it helps, keep the peace, and keep on rockin in the freeworld ted
nugent style.

-CJ
What do you reckon Tom? ;-)

Regards,
Fergus

Nov 20 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1377
by: A. Wiebenga | last post by:
Hi all! I am a student at the Hogeschool van Arnhem en Nijmegen in Holland. I am currently involved in a research project regarding Reflection. Purpose of the research project is to document what Reflection is (I can answer this question myself), what kind of Reflection Techniques there are (.NET Reflection, Python Reflection etc. I can answer this one myself too). The main question I need to answer is related to the implementation of...
10
7364
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a Windows.Forms.UserControl in a COM environment, i.e. I want to host that control in a COM host. So far, so good, I can host it, but I can not reach the parent COM object from the control (Parent property is null :( ). I have stopped the control in the...
1
2624
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am experimenting a bit with what I need to do this and have the following code snippet. But first if I pass the assembly name and type to Activator.CreateInstance() it always fails. However if I walk my assembly and get a type value, the call to...
2
2442
by: Dan | last post by:
Let's say I have a class like: class Dummy { public const string CONE = "one"; public const string CTWO = "two"; ... other stuff .... }
7
371
by: John | last post by:
I have a class the reads in a file and sets the values of the file into its properties. This class is used to populate the data onto a form. This form has controls created at runtime based on user input (file values when file is opened). I was hoping to put the name of the property in the tag of each control and fire an event if the a file is open when the control is created and use the tag to get the correct property from the class. ...
1
2376
by: Pieter Breed | last post by:
Hi All, I am trying to use the attribute/reflection system to as much potential as I can think of, but I've run into a snag. I would appreciate it if someone would point me in the right direction. First my question: How am I supposed to make instances of delegates when I have the method (that I want to make the delegate of) retrieved through reflection?
5
1861
by: heddy | last post by:
I understand that reflection allows me to discover the metadata of a class at runtime (properties, methods etc). What I don't understand is where this is useful. For example: If I am the sole author of an application, I already know the metadata about my classes - I wrote them. And even if I did not - Let's say I buy a 3rd party class lib, it will be documented for me with that lib. If I am part of a dev team, the same is true - If...
5
318
by: =?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?= | last post by:
Hi, is it faster to access the fields from an object directly by using reflection than accessing them by their properties using reflection? Thanks Christian
17
2306
by: raylopez99 | last post by:
What good is C# Reflection, other than to find out what types are in an assembly? And to dynamically invoke methods in an assembly (.dll or .exe)? Also, bonus question, can you use Reflection to build a compiler? One that will construct a user defined class "on the fly" (literally, the user defines a class, instantiates it, and runs it from the console mode, all the while prompted by the program)? I guess so, but my final question...
0
8730
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9064
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3189
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.