I am a novice .NET programmer, and I was hoping to see you and TheMaster debate the questions and points that were raised. Instead, I am disappointed to see that both of you are unwilling to debate. Indeed, Serge, it seems like you are more worried about your pride and hurt feelings than the furtherance of knowledge through critical peer review.
Owen, there's not much to debate other than that the Author really hasn't simply acknowledged that the workaround he highlights in yellow in the screenshot I posted in my first post in this thread, is unnecessary, and that the reason he cites for why the compiler error occurs, is not the case.
There really is no debating something that's entirely self-evident, given a reasonable understanding of the concepts.
Extension methods exposed by one type, look like methods of another type.
The Open() method was a member of the DocumentCollection class in previous releases. In AutoCAD 2013, Open() is a member of another class, but is an extension method that target's the DocumentCollection class, which means the method can be called as if it was still a member of DocumentCollection, and calls to it that worked in AutoCAD 2012 will continue to work in AutoCAD 2013, provided the assembly containing the extension method is referenced.
I would like to know whether TheMaster is correct in his claims that conditional compilation is not necessary to share source code that calls new extension methods. Can someone answer that definitively?
Conditional compilation is
completely unnecessary in cases where the extension methods have the same signature as the methods they replaced in earlier releases. However, some of the new extension methods are actually not replacements for what were methods in AutoCAD 2012. Some of them are replacements for what were
Properties in AutoCAD 2012. For example:
// AutoCAD 2012:
Document doc = Application.DocumentManager.MdiActiveDocument;
object oAcadDocument = doc.AcadDocument;
// AutoCAD 2013:
Document doc = Application.DocumentManager.MdiActiveDocument;
object oAcadDocument = doc.GetAcadDocument();
In the case of the Document.AcadDocument property, Autodesk replaced it with a method (GetAcadDocument). Because the property was replaced with a method, and because properties and methods have a different syntax, there is no way around having to revise code to work on AutoCAD 2013 in those cases, and in the process make it incompatible with AutoCAD 2012. So, in the case where new extension methods are replacing what were properties in AutoCAD 2012, there must be some release-dependent code. Conditional compilation is one way to implement release-dependent code, but not the only way.
If you look at
this post you'll see a workaround that allows you to avoid conditional compilation. The workaround is, quite simply, to provide the same extension methods that Autodesk added to AutoCAD 2013 (to replace properties) to your AutoCAD 2012 project, making those same extension methods available on both releases, and allowing the same consuming code to use them on both releases.
So, with those extension methods from that post added to a project targeting AutoCAD 2012, this code will compile and run on
both AutoCAD 2012 and AutoCAD 2013:
Document doc = Application.DocumentManager.MdiActiveDocument;
object oAcadDocument = doc.GetAcadDocument();
edit: corrected erroneous search/replace 'Document' with 'Application'