'As' is good, since 'is' is really just (obj as type) != null;
But I would probably just use
if( obj is Text )
...
else if( obj is MText )
...
else if( obj is Dimension )
...
There's two casts for each, and its the price we pay to
have code that can deal any type of object derived from
one of those classes, such as various custom objects in
AutoCAD verticals, or newly introduced objects whose
managed classes derive from those being dealt with.
Let's say for example, in the next release of AutoCAD, or
in a vertical flavor, one or more new type(s) of dimension
objects existed, and their managed type was derived from
Dimension. The code Kerry uses would simply ignore them,
becase he is using explicit comparisons against types.
I came across something similar to this when my code was
used on ADT, and found that it was hitting numerous ADT
custom objects that were derived from Curve, and the user
was amazed at how the code was able to deal with those
objects, as well as the regular AutoCAD Curve derivatives
Um... don't you mean:
if( dimObj is Dimension )
Possibly I had typeof on the brain last night and in the cold light of day, I would probably actually use, in this case, 'as' instead...potentially one less cast.
MText mt = dbObj as MText;
If (mt != null) {
// Got some MText - do your mojo here.
}
DBText t = dbObj as DBText;
if (t != null) {
// Got some text - do text mojo here
}
Cheers,
Glenn.