Pergunta

VB2010 with ArcObjects. Im having a problem recalling how to do this. I can test for an object type and then do something if it is the proper type. All else I want to display a message with the type that is not supported. So I have:

Dim pRasRenderer As IRasterRenderer
pRasRenderer = pRasterLayer.Renderer
If TypeOf pRasRenderer Is IRasterClassifyColorRampRenderer Then
  'process the layer
Else
   Debug.Print "Type not supported: " & pRasRenderer.ToString
End If

If not supported the print statement should read

       "Type not supported: IRasterStretchColorRampRenderer"

or any of the other types that I do not process. But All I get back is

       "Type not supported: System.__ComObject"

I tried GetType() and TypeName. Just cant remember if I can do this or not.

Foi útil?

Solução

With COM, the type isn't IRasterStretchColorRampRenderer, it's some COM type that (most likely) implements quite a few distinctly different interfaces. Given that you're working from .NET, you'll get __ComObject any time you try to access the "type" of the object directly.

The actual "type" of the object which implements IRasterStretchColorRampRenderer, for example, is more than likely a native implementation of a COM CoClass. As such, you'll never get a "managed" type name from .NET code for this.

Unfortunately, this means that you're best solution is likely to report that the type passed in is not supported without trying to report the actual type passed into the method. This would likely be something like:

Debug.Print "Type not supported: Current layer is not using a Classify Color Ramp Renderer"
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top