This is exactly what TraitOrDefault<> does.
`rb = building.TraitOrDefault<RepairableBuilding>(); if (rb != null) { }`