as you can tell from post ogf my post's i'm not a programer, just a drafter that tries to write code. that being said if using the com what would be better
option1 or option2. no i'm not trying to do a Regen it's just an example.
any guidance will be appreciated
Option 1
Public ReadOnly Property ThisDrawing() As AcadDocument
Get
Return DirectCast(Application.DocumentManager.MdiActiveDocument.AcadDocument, AcadDocument)
End Get
End Property
Public Sub Test1()
ThisDrawing.Regen(Common.AcRegenType.acAllViewports)
End sub
Option 2
Public Sub Test2()
Dim ThisDrawing As AcadDocument = Application.DocumentManager.MdiActiveDocument.AcadDocument
ThisDrawing.Regen(Common.AcRegenType.acAllViewports)
System.Runtime.InteropServices.Marshal.ReleaseComObject(ThisDrawing)
End sub
They're essentially the same, except that you're eliminating a bit of code.
Normally, when the just-in-time compiler encounters a simple method like the one you show, it will 'inline' the method in the compiled code, meaning that the property you use in Option 1 will end up generating almost the exact same executable code that would be generated if you had directly accessed the AcadDocument, as you do in Option 2.
As to your question about what would be better, my answer would be neither of the two options you show. The reason is, each of them require three property references to get the active AcadDocument object.
The best option IMO, is to cache a reference to the AcadApplication COM object in a shared member of your class, and just read its ActiveDocument property when you need the active AcadDocument, which entails only one property reference rather than three.
The other issue is that your Property in option 1 does not have any dependence on any instance of your class or instance data, so you should probably make it Shared, as that would allow it to be used from instance members and other Shared members of your class.