473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

find Interface

Hi

How to find out in templated class if a type is implementing an interface.
In particular I want to find out whether the type passed is a INullableValue

I came up with somethig like this:
class myClass<PropertyT>
{
public DoSomething() {
if ( typeof(PropertyT).GetInterface(typeof(INullableVal ue).ToString())
!= null ) {
// PropertyT is INullable
}
}
}

is there a simpler way?

CUIN Kaczy
Nov 17 '05 #1
2 2087
Hi,

If you have an instance of PropertyT you can do this:

PropertyT instance;

INullableValue var = instance as INullableValue
if ( var != null )
// PropertyT is INullable
If all you have to work are the types (not any instance) then I thikn that
your way is the way to go
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Andrzej Kaczmarczyk" <ak**********@visualsystems.com.pl> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi

How to find out in templated class if a type is implementing an interface.
In particular I want to find out whether the type passed is a
INullableValue

I came up with somethig like this:
class myClass<PropertyT>
{
public DoSomething() {
if ( typeof(PropertyT).GetInterface(typeof(INullableVal ue).ToString())
!= null ) {
// PropertyT is INullable
}
}
}

is there a simpler way?

CUIN Kaczy

Nov 17 '05 #2


Ignacio Machin ( .NET/ C# MVP ) wrote:
If you have an instance of PropertyT you can do this:


actually, you can just do:

if ( instance is PropertyT )

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Nov 17 '05 #3

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

Similar topics

1
by: David | last post by:
My customer wants to scan their documents and organize them electronically and he has asked me to find him a viable solution. These are the criteria. - It must integrate with an existing MS SQL...
3
by: Brian Fulford | last post by:
I am trying to deploy a web app with a deployment project since I am including Crystal Reports for .Net. I attached all the merge modules, etc but I am getting a build error when I try to build...
2
by: glenn | last post by:
Can anyone tell me a good resource to find user interface components for VS 2003? I specifically need nice look field and grid components, drop down lists, calendar components and so on. I'm...
29
by: chellappa | last post by:
hi all I need to write a program to find mac address of a my computer using libaries, is this possible? How? thanks
4
by: chellappa | last post by:
hi all, i trying to find the intferface name using this coding ,but that is not working ,,,if anybody this pervious..please help to find the interface name using Linux C. //CODE ioctl(sd,...
7
by: Nadav | last post by:
Hi, 1. I am writing some kind of a CLI Linker 2. I am using the unmanaged meta-data API. I wonder browsing "cor.h" I have encountered the 'ICeeGen' this interface is retrieved by the...
5
by: Mike Labosh | last post by:
In VB 6, the Form_QueryUnload event had an UnloadMode parameter that let me find out *why* a form is unloading, and then conditionally cancel the event. In VB.NET, the Closing event passes a...
1
by: skootr | last post by:
I have a Public Interface defined in a class module. I also have a form that implements that interface After building the solution, I added an Inherited Form (inherited from the above-mentioned...
5
by: SunnyDrake | last post by:
HI! I wrting some program part of it is XML config parser which contains some commands(for flexibility of engenie). how do i more simple(if it possible not via System.Reflection or...
5
by: Random | last post by:
How can I use reflection (or some other method) to find the type of an object that has been passed in to my method under an interface definition? I try to use GetType, but that won't work.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.