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 12 2366
On 3 Oct 2003 15:06:28 -0700, to************* ***@hotmail.com (Antony)
wrote: If asmblyType.Base Type.Equals(Get Type(Interface0 1)) Then Debug.Write("Ye s: ")
No base type would cause your problem. Use the Type.GetInterfa ces()
collection instead.
Hi Antony,
Furthermore:
SomeType.BaseTy pe will give you the <class> that SomeType inherited from.
It will never give you an interface as these cannot be inherited.
Regards,
Fergus
Hi, an implemented interface isn't a base type, because you can implement as
many interfaces as you want:
Public Class Class01
Implements Interface01
Implements Interface02
Andy, Fergus - that is clear now. Thank you.
Tony
"Fergus Cooney" <fi******@tesco .net> wrote in message news:<eO******* *******@TK2MSFT NGP10.phx.gbl>. .. Hi Antony,
Furthermore:
SomeType.BaseTy pe will give you the <class> that SomeType inherited from. It will never give you an interface as these cannot be inherited.
Regards, Fergus
Thanks Tom.
Just one more thing, if I modify my code (below) it prints out the
names of all classes etc. in a /*project*/. Is it possible to print
out the names of all classes using similar code in a /*solution*/ ?
Thank you
Tony
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
Debug.WriteLine (asmblyType.Ful lName)
Next
End Sub
"Tom Spink" <th**********@n tlworld.com> wrote in message news:<en******* *******@TK2MSFT NGP10.phx.gbl>. .. Hi, an implemented interface isn't a base type, because you can implement as many interfaces as you want:
Public Class Class01 Implements Interface01 Implements Interface02 . . . Implements Interface99 End Class
So, your code should be:
' /// (See footnotes to convert to VS2002) Private Sub MySub() Dim asmThis As [Assembly] = [Assembly].GetExecutingAs sembly() Dim blnFoundInterfa ce As Boolean
For Each typType As Type In asmThis.GetType s
blnFoundInterfa ce = False
For Each typInterface As Type In typType.GetInte rfaces If typInterface Is GetType(Interfa ce01) Then blnFoundInterfa ce = True Exit For End If Next
If blnFoundInterfa ce Then Debug.Write("Ye s: ") Else Debug.Write("No : ") End If
Debug.WriteLine (typType.FullNa me)
Next
End Sub ' ///
-- HTH, -- Tom Spink, Über Geek
Please respond to the newsgroup, so all can benefit
" System.Reflecti on Master "
==== Converting to 2002 ==== Remove inline declarations
Antony schriebt, : 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
One Project is one assembly, a solution can contain many assemblies. You'd
have to perform reflection on all referenced assemblies, by dynamically
loading them.
If your project doesn't reference an assembly, (and you are using .NET 1.1)
then you can call [Assembly].LoadFile to load it into an Assembly object,
then run the code on that assembly.
If you are using .NET 1.0, there is the .Load method, which requires the
fully qualified name of the Assembly.
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
" System.Reflecti on Master "
==== Converting to 2002 ====
Remove inline declarations
"Antony" <to************ ****@hotmail.co m> wrote in message
news:37******** *************** ***@posting.goo gle.com...
: Thanks Tom.
:
: Just one more thing, if I modify my code (below) it prints out the
: names of all classes etc. in a /*project*/. Is it possible to print
: out the names of all classes using similar code in a /*solution*/ ?
:
: Thank you
: Tony
:
:
: 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
: Debug.WriteLine (asmblyType.Ful lName)
: Next
: End Sub
:
:
:
:
:
:
: "Tom Spink" <th**********@n tlworld.com> wrote in message
news:<en******* *******@TK2MSFT NGP10.phx.gbl>. ..
: > Hi, an implemented interface isn't a base type, because you can
implement as
: > many interfaces as you want:
: >
: > Public Class Class01
: > Implements Interface01
: > Implements Interface02
: > .
: > .
: > .
: > Implements Interface99
: > End Class
: >
: > So, your code should be:
: >
: > ' /// (See footnotes to convert to VS2002)
: > Private Sub MySub()
: > Dim asmThis As [Assembly] = [Assembly].GetExecutingAs sembly()
: > Dim blnFoundInterfa ce As Boolean
: >
: > For Each typType As Type In asmThis.GetType s
: >
: > blnFoundInterfa ce = False
: >
: > For Each typInterface As Type In typType.GetInte rfaces
: > If typInterface Is GetType(Interfa ce01) Then
: > blnFoundInterfa ce = True
: > Exit For
: > End If
: > Next
: >
: > If blnFoundInterfa ce Then
: > Debug.Write("Ye s: ")
: > Else
: > Debug.Write("No : ")
: > End If
: >
: > Debug.WriteLine (typType.FullNa me)
: >
: > Next
: >
: > End Sub
: > ' ///
: >
: > --
: > HTH,
: > -- Tom Spink, Über Geek
: >
: > Please respond to the newsgroup,
: > so all can benefit
: >
: > " System.Reflecti on Master "
: >
: > ==== Converting to 2002 ====
: > Remove inline declarations
: >
: >
: > Antony schriebt,
: > : 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
Hi Tom,
Is there any class which can provide a list of the Assemblies within the
Soloution?
Regards,
Fergus
Hi Fergus,
A Solution isn't compiled into anything, a solution has no meaning in .NET,
it is simply a Visual Studio term for a collection of projects. A Project
could be an assembly, e.g. a C#, J#, VB.NET assembly, or it could be
something completely different like a Help File.
So basically, no, because a solution means nothing in .NET.
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
" System.Reflecti on Master "
==== Converting to 2002 ====
Remove inline declarations
"Fergus Cooney" <fi******@tesco .net> wrote in message
news:ua******** *****@TK2MSFTNG P11.phx.gbl...
: Hi Tom,
:
: Is there any class which can provide a list of the Assemblies within
the
: Soloution?
:
: Regards,
: Fergus
:
:
Hi Fergus, yes this is what I am looking for too.
I have a "good feeling" about :
For Each aAll As [Assembly] In AppDomain.Curre ntDomain.GetAss emblies()
'Code in here
Next
but I can't get it going and my underlying feeling is that Tom is on
the right when he says "No".
Cheers
Tony
"Fergus Cooney" <fi******@tesco .net> wrote in message news:<ua******* ******@TK2MSFTN GP11.phx.gbl>.. . Hi Tom,
Is there any class which can provide a list of the Assemblies within the Soloution?
Regards, Fergus This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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 ....
}
|
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. ...
| |
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?
|
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...
|
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
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |