How to get LINQPad to Dump() System.__ComObject references?

前端 未结 1 752
生来不讨喜
生来不讨喜 2021-01-06 00:50

I am playing around with using LINQPad to rapidly develop small ArcObjects (a COM-based library for ESRI\'s ArcGIS software) applications and have had some success in using

相关标签:
1条回答
  • 2021-01-06 01:44

    I've been having some of the same issues (except I'm working with iTunes COM library).

    In visual studio you don't realize it but each debug window is asking the COM library to create the type when you open it. This is different than Dump() which is, well, not interactive.

    The only solution I've found is if I know what type the list is to do a OfType<>() cast to that type. This will iterate over the list and force COM to create the elements.

    So in your example above you would say:

    var layers = map.EnumerateLayers("etc")
          .Select(s => s.OfType<Layer>())
          .Dump();
    

    NB - Your millage may vary, it turns out for the OP example this was needed.

    var layers = map.EnumerateLayers()
          .OfType<IGeoFeatureLayer>()
          .Dump();
    

    Depending on the COM you might have to take this to the next step and pull out the members from there (with com you have to ask to get the value) something like this:

    var layers = map.EnumerateLayers("etc")
          .Select(x => x.OfType<Layer>())
          .Select(x => new { x.Depth, x.Dimention, }) // etc 
          .Dump();
    

    Sure would be nice if there was a "magical" way to make this happen, but I don't believe there is because of the nature of COM.

    0 讨论(0)
提交回复
热议问题