Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/ACadSharp.Tests/CadDocumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,19 @@ public void SetCurrentTest()
doc.SetCurrent(new MultiLeaderStyle(multiLeaderStyleName));
Assert.True(doc.MLeaderStyles.ContainsKey(multiLeaderStyleName));
}

[Fact]
public void TryGetCadObjectTypeMismatch()
{
CadDocument doc = new CadDocument();

Line line = new Line();
doc.Entities.Add(line);

Assert.True(doc.TryGetCadObject(line.Handle, out Line found));
Assert.Equal(line, found);

Assert.False(doc.TryGetCadObject(line.Handle, out Circle circle));
Assert.Null(circle);
}
}
4 changes: 2 additions & 2 deletions src/ACadSharp/CadDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@ public bool TryGetCadObject<T>(ulong handle, out T cadObject)
if (handle == this.Handle)
return false;

if (this._cadObjects.TryGetValue(handle, out IHandledCadObject obj))
if (this._cadObjects.TryGetValue(handle, out IHandledCadObject obj) && obj is T)
{
cadObject = obj as T;
cadObject = (T)obj;
return true;
}

Expand Down
Loading