473,657 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Testing class type

I want to pass the type of an object as a field in an object.

public class FileEventArgs : EventArgs

{

public object Data = null;

public Type ClassType = null;

}

In another function, I want to test ClassType. Depending on the Class Type
Data is handled differently.

I can't work out the correct way to do it - the following doesn't work, can
someone help please.

I could do it another way easily but I now wonder what Im doing wrong.

if (e.ClassType == DI225.SerialDri ver)

Converter = new DI225.Converter ();

else if (e.ClassType == PPC.Driver)

Converter = new PPC.Converter() ;


Nov 16 '05 #1
2 1584
Assuming you're setting the ClassType member with <object>.GetTyp e(), to
compare use:

if(e.ClassType == typeof(DI225.Se rialDriver))
....

--Liam.

"Claire" <as*******@ntlw orld.com> wrote in message
news:uP******** ******@TK2MSFTN GP10.phx.gbl...
I want to pass the type of an object as a field in an object.

public class FileEventArgs : EventArgs

{

public object Data = null;

public Type ClassType = null;

}

In another function, I want to test ClassType. Depending on the Class Type
Data is handled differently.

I can't work out the correct way to do it - the following doesn't work, can someone help please.

I could do it another way easily but I now wonder what Im doing wrong.

if (e.ClassType == DI225.SerialDri ver)

Converter = new DI225.Converter ();

else if (e.ClassType == PPC.Driver)

Converter = new PPC.Converter() ;

Nov 16 '05 #2
Hi Claire
You can use either the "Is" keyword or the "As" keyword to check for the
type.
Is operator checks if an object of some type and the expression returns a
Boolean ( object_A Is String ) . while the as operator try to cast an
object to another and return null if the cast is not doable , you can use
that as a test too .
hope this helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #3

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

Similar topics

2
2090
by: Edvard Majakari | last post by:
Hi all ya unit-testing experts there :) Code I'm working on has to parse large and complex files and detect equally complex and large amount of errors before the contents of the file is fed to module interpreting it. First I created a unit-test class named TestLoad which loaded, say, 40 files of which about 10 are correct and other 30 files contained over 20 different types of errors. Different methods on the TestLoad class were coded so...
0
1193
by: Matt | last post by:
Hi All. I have been trying to implement this front controller On MS site and finally i have no error on the pages but i dont its working or not. When i execute the pages from Browser i dont get no result. I have hard coded the Database getting site name part still no luck. I have try to write the context that i am passing, seems empty. If someone pls help me out with testing this i would appriciate it. May be someone can post the working...
4
1920
by: a | last post by:
I'm having trouble testing a custom object. I've tried many different approaches. One is shown below. The XML below shows the state of the object and I'm trying to test for that state, ie there are NO classes in the Classes collection (Classes) of the custom object. The conditional expression returns the error shown below it... =======================================================XML returned by
5
3932
by: David K Allen | last post by:
Here's my problem. Have a database interface with several methods. I created a database class to implement the interface, and a set of unit tests to test each method. Now I want to support another database provider. The implementation is very easy: I simply create a new database class, and implement all the methods using the new database provider. My question is: How do I get this same set of unit tests to run in a loop? My problem is...
3
2437
by: Joe Van Dyk | last post by:
Say I've written a class that wraps around a particular (complex) communication service library. I want to unit test objects that use that communication service. Is the "best practice" to create a Communication_Service abstract base class that my Concrete_Communication_Service and my Mock_Communication_Service both inherit from? (and then use the mock service when unit testing)
12
3133
by: Noah Roberts | last post by:
I'm using a simple unit test architecture I found in "Thinking in C++". I just decided I wanted to place some member functions out from public into a protected scope. Problem is that my tests want to access those functions...bummer. What have other people done when faced with this problem or just the general problem of testing functionality encapsulated in a private manner?
44
2845
by: John A. Bailo | last post by:
Dr. Dobbs has a /glowing/ article on Ruby on Rails this month. What do you guys think? Can it replace .net, php and java? And be the Open Source OOP web solution that is not bound to Sun or MS? http://media.rubyonrails.org/presentations/pursuitofbeauty.pdf
1
1367
by: iLL | last post by:
If I have a collection of polymorphic objects, is there a way to test exactly what data type an element of that collection is? I’ve though of two workarounds: 1. Type casting and testing thought exception handling. 2. Adding a String to the root class that represents the data type. But if there is a conventional way of testing this, I would rather use that. I’ve tried doing a Google search on polymorphism data type testing, but it...
4
1140
by: Emanuele D'Arrigo | last post by:
Hi everybody, I'm just having a go with Unit Testing for the first time and my feeling about it in short is: Neat! I'm a bit worried about the time it's taking me to develop the tests but after only a day or so I'm already much faster than when I started with it and the code is already much improved in terms of robustness. A couple of "philosophical" questions have emerged in the process.
3
2206
by: ibeehbk | last post by:
Hi. I have a form made in xhtml. I test via vbscript to make sure none of the fields are empty and properly formatted (ie email). All the regular fields work. However, I have two drop down menus that are SELECT elements (javascript-- one named arrivalcity and one named returncity). Basically they ask for a departure and return city and another menu appears with options based on that city. I can't seem to get the input from these fields in the...
0
8402
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
8315
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
8829
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...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7341
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...
0
5633
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
4164
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
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1627
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.