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

Home Posts Topics Members FAQ

Knowing an object implements an Interface

Hi,

Is there a quick way to know if a given object implements IComparable?
(without casting or anything like that). Something that uses reflection?

Thanks
-Ron
Jun 29 '06 #1
3 1446
Ron M. Newman wrote:
Hi,

Is there a quick way to know if a given object implements IComparable?
(without casting or anything like that). Something that uses reflection?

Thanks
-Ron


If(myObject is IComparable)

....

or via reflection.
Type.GetInterfa ce(interfaceNam e).
Jun 29 '06 #2
Ron M. Newman wrote:
Hi,

Is there a quick way to know if a given object implements IComparable?
(without casting or anything like that). Something that uses reflection?

Thanks
-Ron


Hi Ron,

You can use the 'is' operator to test whether or not the given object will
cast to the given type:

if ( obj is IComparable ) { ... }

'obj is IComparable' will evaluate to true if obj can be cast to an
IComparable, i.e. if it implements the IComparable interface.

--
Hope this helps,
Tom Spink
Jun 30 '06 #3
Ron M. Newman wrote:
Hi,

Is there a quick way to know if a given object implements IComparable?
(without casting or anything like that). Something that uses
reflection?


casting under the CLR uses reflection (well, type meta-data, not the
relfection API per-se), so you're tilting against windmills trying to do it
"without casting or anything like that". Just use the 'is' operator in C#
(trycast in IL).

-cd
Jun 30 '06 #4

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

Similar topics

3
3402
by: Jeff Molby | last post by:
Ok, I've googled long and hard, but I can't find anything relevant on this one. I am now at the mercy of your good nature. <g> I have 3 projects in my solution: One app and 2 libraries. I am basically attempting to create a "plug-in" feature for my app. Namespace A contains the plug-in interface Namespace B is a sample implementation of that interface. The application needs to be able to load the implementation in Namespace B
16
25404
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have the properties: mode1, mode2, and mode3. This seems simple but I can't quite figure it out... Any ideas anyone?
11
4183
by: Robin Tucker | last post by:
I have a COM object, which implements straightforwardly the IDataObject interface. It seems this isn't the same IDataObject interface we now have with .NET. Basically, the COM object implements low level interfaces. It does not have a type library. We use it freely with our unmanaged C++ projects. What I would like to do is load or create one of these objects in VB.NET, but I cannot seem to do it. I've tried: Dim theObject As...
11
2208
by: Antony | last post by:
I know this sounds stupid but I am going to carry on anyway. I want to create an interface that implements all methods of a form, plus another one or two. But I need to know if there is an interface that defines all a forms methods etc. In the example below "System.Windows.Forms.Form" isn't an interface, but it gets my point across. Is there an interface for a form that I can substitute here? Thank you again Tony
6
2555
by: solex | last post by:
Hello, I am trying to use serialization to copy objects. The object in question "Institution" inherits from a parent object "Party" both are marked as <Serializable()>. Initially I can copy an empty Institution to another empty Institution, using the following routine: Private Sub CopyObject(ByRef FromObject As Object, ByRef ToObject As Object) Dim m As New MemoryStream Dim b As New BinaryFormatter
8
5726
by: Joe Johnston | last post by:
I need a Browser Helper object written in VB.NET Please point me at a good example. Joe MCPx3 ~ Hoping this MSDN ng three day turnaround is true. Additional info: What is a BHO? In its simplest form, a BHO is a COM in-
1
1665
by: Lucile | last post by:
Hi to All, I am new to this newsgroup, so please bare with me. Here is the deal: I have the following Object Graph: Icell (Interface) Iline (Interface) Itable (Interface) Classes: Cell: implements Icell Line: inherits Arraylist Implements Iline
2
3413
by: lothar.behrens | last post by:
Hi, I am trying to load an assembly at runtime (plugin). Having the object (as Object), I like to cast it to the interface. The interface is defined as follows: Public Interface IVoimDescriptor Function getVendorName() As String Function getVoimDescription() As String '...
16
2089
by: Alex | last post by:
Hello, I'm trying to use a (remote) COM object from a PHP script (4.4, server has apache2 win32). The basics seem to work : I instantiate the COM object ($o = new COM"..."), then I use two of the objects methods to authenticate. In the meantime a property called "ProjectConnected", passes from 0 to 1. So I think the object is correctly instanciated and the connection works.
0
8312
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
8827
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
8732
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...
1
8504
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,...
1
6169
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
5632
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
4159
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
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1622
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.