wtertinek / Linq2Acad

A library that aims to simplify AutoCAD .NET plugin code
MIT License
61 stars 34 forks source link

EntityContainer allows access to objects of other EntityContainers #31

Open wtertinek opened 1 year ago

wtertinek commented 1 year ago

Expected Behavior

I'm expecting EntityContainer.Element(ObjectId) and EntityContainer.ElementOrDefault(ObjectId) to return only Entities that are children of the container.

Current Behavior

Currently it is possible to get an Entity that is present on a PaperSpace layout via the ModelSpace (see sample code below).

Context

Failure Information

The failure does not produce an error in the AutoCAD API. It is just a wrong behavior of Linq2Acad.

Sample Code

using (var db = AcadDatabase.Active())
{
  // We expect to have an Entity in the paper space
  var paperSpaceEntity = db.PaperSpace.First().First();

  var _ = db.ModelSpace.Element(paperSpaceEntity.ObjectId);
  System.Diagnostics.Debug.Fail("No exception thrown");
  // The above call should actually throw an exception because paperSpaceEntity is not present in the model space

  var result = db.ModelSpace.ElementOrDefault(paperSpaceEntity.ObjectId);
  System.Diagnostics.Debug.Assert(result == null);
  // result should actually be null because paperSpaceEntity is not present in the model space
}

Checklist