Well, it does not seem to be so simple? The following snippet:
Type attrType = typeof(System.Xml.XmlAttribute);
Type nodeType = typeof(System.Xml.XmlNode);
if (attrType == nodeType)
Console.WriteLine("is an instance of XmlNode");
else
if (nodeType.IsAssignableFrom(attrType))
Console.WriteLine("XmlNode is assignable from this type");
produces "XmlNode is assignable from this type". XmlNode is an abstract
class, so type equality cannot be true. Instead, IsAssignableFrom() should
be used. From the docs:
Type.IsAssignableFrom
Return Value
true if the c parameter and the current Type represent the same type, or if
the current Type is in the inheritance hierarchy of c, or if the current
Type is an interface that c supports. false if none of these conditions are
the case, or if c is a null reference (Nothing in Visual Basic).
So, use
typeof(System.Xml.XmlNode).IsAssignableFrom(parameters[0].ParameterType)
Marek
----- Original Message -----
From: "Shawn A. Van Ness" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 27, 2004 9:53 PM
Subject: Re: [ADVANCED-DOTNET] Depending on what your definition of is is...
> if (parameters[0].ParameterType == typeof(System.Xml.XmlNode))
>
> -S
>
> On Wed, 27 Oct 2004 15:34:11 -0400, Jekke Bladt <[EMAIL PROTECTED]>
wrote:
> > I've been thinking along those lines. If that's the case, how would I
> > check for whether or not the Type returned represents XmlNode?
> >
> > --Jekke
>
> ===================================
> This list is hosted by DevelopMentor� http://www.develop.com
> Some .NET courses you may be interested in:
>
> Essential .NET: building applications and components with C#
> November 29 - December 3, in Los Angeles
> http://www.develop.com/courses/edotnet
>
> View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentor� http://www.develop.com
Some .NET courses you may be interested in:
Essential .NET: building applications and components with C#
November 29 - December 3, in Los Angeles
http://www.develop.com/courses/edotnet
View archives and manage your subscription(s) at http://discuss.develop.com