473,803 Members | 3,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compare inteface Type with each other

Hi

Look at the TODO in the code. The commented code do not work, but the code
below the commented one does. How do I do to compare Types?

foreach (Type typeInAssembly in typesInAssemply )
{
// typeLoadExcepti on.Types can generate null values.
if (typeInAssembly != null && !typeInAssembly .IsAbstract)
{
foreach (Type interfaceType in typeInAssembly. GetInterfaces() )
{
//TODO: Whats wrong with this: if (interfaceType ==
typeof(IInstrum entAdministrato r) ???
if (interfaceType. Name == typeof(IInstrum entAdministrato r).Name)
{
typesWithInterf ace.Add(typeInA ssembly);
}
}
}
}

Regards
/Niklas
Dec 22 '06 #1
4 2082
You could use :
The t.TypeHandle.Va lue property from each type to compare.
--
Ciaran O''''Donnell
http://wannabedeveloper.spaces.live.com
"Niklas" wrote:
Hi

Look at the TODO in the code. The commented code do not work, but the code
below the commented one does. How do I do to compare Types?

foreach (Type typeInAssembly in typesInAssemply )
{
// typeLoadExcepti on.Types can generate null values.
if (typeInAssembly != null && !typeInAssembly .IsAbstract)
{
foreach (Type interfaceType in typeInAssembly. GetInterfaces() )
{
//TODO: Whats wrong with this: if (interfaceType ==
typeof(IInstrum entAdministrato r) ???
if (interfaceType. Name == typeof(IInstrum entAdministrato r).Name)
{
typesWithInterf ace.Add(typeInA ssembly);
}
}
}
}

Regards
/Niklas
Dec 22 '06 #2
Because when you refer to "interfaceType" , you are refering to the object,
not the objects type... try using "interfaceType. GetType()"

Adam - http://www.aejw.com/?page=contact
"Niklas" <Ni****@discuss ions.microsoft. comwrote in message
news:86******** *************** ***********@mic rosoft.com...
Hi

Look at the TODO in the code. The commented code do not work, but the code
below the commented one does. How do I do to compare Types?

foreach (Type typeInAssembly in typesInAssemply )
{
// typeLoadExcepti on.Types can generate null values.
if (typeInAssembly != null && !typeInAssembly .IsAbstract)
{
foreach (Type interfaceType in typeInAssembly. GetInterfaces() )
{
//TODO: Whats wrong with this: if (interfaceType ==
typeof(IInstrum entAdministrato r) ???
if (interfaceType. Name ==
typeof(IInstrum entAdministrato r).Name)
{
typesWithInterf ace.Add(typeInA ssembly);
}
}
}
}

Regards
/Niklas
Dec 22 '06 #3
If you do interfaceType.G etType() that is going to return a
System.RuntimeT ype, since it is the type of the Type in question :-) which is
not going to help the issue. I believe the problem the OP may be having is
that the fully qualified names of the type do not match because they have
different values for the module.

Mark
--
http://www.markdawson.org
http://themightycoder.spaces.live.com
"aejw.com" wrote:
Because when you refer to "interfaceType" , you are refering to the object,
not the objects type... try using "interfaceType. GetType()"

Adam - http://www.aejw.com/?page=contact
"Niklas" <Ni****@discuss ions.microsoft. comwrote in message
news:86******** *************** ***********@mic rosoft.com...
Hi

Look at the TODO in the code. The commented code do not work, but the code
below the commented one does. How do I do to compare Types?

foreach (Type typeInAssembly in typesInAssemply )
{
// typeLoadExcepti on.Types can generate null values.
if (typeInAssembly != null && !typeInAssembly .IsAbstract)
{
foreach (Type interfaceType in typeInAssembly. GetInterfaces() )
{
//TODO: Whats wrong with this: if (interfaceType ==
typeof(IInstrum entAdministrato r) ???
if (interfaceType. Name ==
typeof(IInstrum entAdministrato r).Name)
{
typesWithInterf ace.Add(typeInA ssembly);
}
}
}
}

Regards
/Niklas
Dec 23 '06 #4
I don't think nUnit has any problem, but someting with your codes setup. Is
the IInstrumentatio nAdministrator interface defined in a single file that is
compiled separately into the assembly you loaded and referenced by the
executing code. If this is the case then when you are iterating through the
types from the loaded assembly you will get to a
IInstrumentatio nAdministrator type but its fully qualified name will include
the module it came from i.e. myAssembly1.dll , whereas you executing code is
in a different module i.e. myExecutable.ex e ad if that one included the
interface definition .cs file then when you say
typeof(IInstrum entationAdminis trator) then the module of that type is going
to be myExecutable.ex e, hence when you compare the two types they are
considered to be different because their modules are different. The code
would work for the .Name comparison since that compares just the simple name
of the type which is not taking into account the module name.

This is just my guess, if you break in the debugger on the line where you
compare the types and it is failing, look at the module name and see if they
are different.

Mark.
--
http://www.markdawson.org
http://themightycoder.spaces.live.com

"Niklas" wrote:
Hi
I found the problem...nUnit . In nUnit (interfaceType ==
typeof(IInstrum entAdministrato r) this is false, but if I run the same code in
a Console application it is true.
Regards
/Niklas

"Niklas" wrote:
Hi

Look at the TODO in the code. The commented code do not work, but the code
below the commented one does. How do I do to compare Types?

foreach (Type typeInAssembly in typesInAssemply )
{
// typeLoadExcepti on.Types can generate null values.
if (typeInAssembly != null && !typeInAssembly .IsAbstract)
{
foreach (Type interfaceType in typeInAssembly. GetInterfaces() )
{
//TODO: Whats wrong with this: if (interfaceType ==
typeof(IInstrum entAdministrato r) ???
if (interfaceType. Name == typeof(IInstrum entAdministrato r).Name)
{
typesWithInterf ace.Add(typeInA ssembly);
}
}
}
}

Regards
/Niklas
Dec 23 '06 #5

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

Similar topics

4
5130
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows for each record, each row accounts for a different type of outcome I'm having trouble with MySQL date comparison. I'm looking for some kind of query that will compare the all date column and only give me the latest date. Then once I have it, ...
4
5395
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
11
9731
by: Russ Green | last post by:
How does this: public TimeSpan Timeout { get { return timeout; } set { timeout = value; if(timeout < licenseTimeout) licenseTimeout = timeout; }
5
6343
by: rcolby | last post by:
Evening, Wondering if someone can point me in the right direction, on how I would compare a system.guid with a system.byte. system.guid (pulled from sql server table with a data type of uniqueidentifier, originally taken from objectGUID from active directory domain)
7
12900
by: Prabhudhas Peter | last post by:
I have two object instances of a same class... and i assigned values in both object instances (or the values can be taken from databse and assigned to the members of the objects)... Now i want to compare these two objects so that it will return true if both object's members have the same value... it is good if u can give me a single function or simple code snippet.. Thank U -- Peter...
5
37874
by: Jason | last post by:
Is there a mechanism in VB.NET that allows something like: If myVar In ("A","B","C") Then... The way I'm doing it now is: Select Case myVar Case "A","B","C" Or like this:
8
1211
by: Marius Horak | last post by:
I've never used Interface and never will. But now I have to make major modifications to a large system where almost all classes are based on some kind of Interface. Hundreds of classes. When I want do add a new property or method I have to modify the interface and next I have to modify dozens of other classes or create new inteface. Sooner or later I will finish having a single class based on its own interface. So what is the point of...
5
2674
by: Edd E | last post by:
Hi, I have a database to store my analyses (Access 2002, WinXp), the basic structure is: TABLE 1 = Sample Info TABLE 2 = Analysis type 1 TABLE 3 = Analysis type 2 TABLE 4 = Analysis type 3 ....where each table stores results of a different type of analysis
5
3972
by: S S | last post by:
Hi I have a requirement where I am declaring a map within a class. class abc { map <void*, void*mMap; // I do not pass compare struct here. .... }; Here I am not passing compare function, but I want to do it into the
0
9703
marktang
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...
0
9564
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
10548
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
9125
agi2029
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...
1
7604
isladogs
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...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
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
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.