c# - Class not inheriting from object? -
i working on method using reflection inspect parameter types of methods. methods iterates through parameterinfo's , doing types of parameters.
i under assumption if typeinfo.isclass
true
, type class , derives (indirectly) type object
(except when type object
of course). so, if typeinfo.isclass
true, typeinfo.basetype
must set.
well assumption wrong! there classes not derive type object
. , assumption messed code.
for example:
type type = typeof(int).makebyreftype();
type.isclass
true
, type.basetype
null
.
if think it, logical. , can prevent code crash checking typeinfo.isbyref
.
now question is: there more such 'exotic' types (besided byref-types , type object
) class (isclass == true
) not have base type (basetype == null
)?
before answer: refering types isclass == true
! , example type int
example. have been type. please no:
- interfaces
- structs
- void
answers far:
- byref types (
t&
): descrybed in question. - pointer types (
t*
): found mark gravell.
i isclass
misleading here. states:
gets value indicating whether system.type class; is, not value type or interface.
and implemented way: checks whether flags include interface
, , whether valuetype
.
unfortunately, there more things this. pointers are not managed types. by-ref similar pointer. pointer not object
s, although in common use cast de-reference/cast. same applies things direct pointers such int*
.
not in .net object
:)
var basetype = typeof(int*).basetype; // null bool liesandmorelies = typeof(int*).isclass; // true
eric lippert covers more here: not derives object - , lists few other examples (open generic types, example).
Comments
Post a Comment