Yes, we can use DynamicBlockTableRecord property to get the blockreference's BlockTableRecord regardless the blockreference being regular block or being dynamic block. However, when doing so, we need to open one more object (BlockTableRecord) to get block name inside the transaction, which is not necessary if the block is not a dynamic block. So, I'd still prefer to test IsDynamicBlock property first.
To the OP: the code is really very simple, that was why I wrote psuedo code above. But since you ask, here you go:
[CommandMethod("MyCmd")]
public static void MyCmd()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
string blkName = PickBlock(ed);
ed.WriteMessage("\nPicked block is {{0}\n", blkName);
}
private static string PickBlock(Editor ed)
{
string blkName = "";
PromptEntityOptions opt = new PromptEntityOptions("\nPick a block:");
opt.SetRejectMessage("Bad pick: must be a block");
opt.AddAllowedClass(typeof(BlockReference), true);
PromptEntityResult res = ed.GetEntity(opt);
if (res.Status == PromptStatus.OK)
{
using (Transaction tran = res.ObjectId.Database.TransactionManager.StartTransaction())
{
BlockReference blk = tran.GetObject(res.ObjectId, OpenMode.ForRead) as BlockReference;
if (blk != null)
{
if (blk.IsDynamicBlock)
{
BlockTableRecord br = tran.GetObject(blk.DynamicBlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
blkName = br.Name;
}
else
{
blkName = blk.Name;
}
}
tran.Commit();
}
}
return blkName;
}