Just a reminder regarding
'Collection Initialization' DBObjectCollection acDBObjColl
= new DBObjectCollection
(); acDBObjColl.Add(acLine1);
acDBObjColl.Add(acLine2);
acDBObjColl.Add(acCirc2);
acDBObjColl.Add(acMText4);
Since c#6 Can become
DBObjectCollection acDBObjColl
= new DBObjectCollection
{
acLine1,
acLine2,
acCirc2,
acMtext4
};
We can also use it when constructing in a using statement :
but I think it could lead to confusion, so I won't use it.
// Create a circle that is at 2,3 with a radius of 4.25
using (Circle acCirc
= new Circle
{
Center
= new Point3d
(2,
3,
0),
Radius = 4.25
})
{
// Add the new object to the block table record and the transaction
acModelSpaceRec.AppendEntity(acCirc);
acTrans.AddNewlyCreatedDBObject(acCirc, true);
< . . . . >
This compiles to the following. It's interesting how the compiler shuffles the (Decompiled/Reflected) code
[CommandMethod("CopySingle")]
public static void CopySingle()
{
Document document = Application.get_DocumentManager().get_MdiActiveDocument();
Database database = document.get_Database();
using (Transaction transaction = database.get_TransactionManager().StartTransaction())
{
BlockTableRecord record = transaction.GetObject((transaction.GetObject(database.get_BlockTableId(), 0)
as BlockTable).get_Item(BlockTableRecord.ModelSpace), 1)
as BlockTableRecord;
Circle circle1
= new Circle
(); circle1
.set_Center(new Point3d
(2.0,
3.0,
0.0)); circle1.set_Radius(4.25);
using (Circle circle = circle1)
{
record.AppendEntity(circle);
transaction.AddNewlyCreatedDBObject(circle, true);
Circle circle2 = circle.Clone() as Circle;
circle2.set_Radius(1.0);
record.AppendEntity(circle2);
transaction.AddNewlyCreatedDBObject(circle2, true);
}
transaction.Commit();
}
}
Coming back to this stuff I'm reminded of the axiom "use it or lose it"
... the wet grey stuff doesn't keep knowledge we don't use and reinforce regularly.