Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current implementation of
GetDeviceContext
andGetPassthroughDeviceContext
explicitly receives the device ID as a numerical argument. While functionally sound, this approach makes it harder to generate informative error messages, since there is no way to map the ID back to a device name.This PR refactors this approach to instead receive the expected device type. The numerical device ID is then extracted directly from the type metadata by searching for a literal field with the name
ID
. If no such field is found, or a device with an invalid ID is detected, the exception will now contain the type name.The change also establishes parity between
ContextHelper.GetDeviceContext
andDeviceInfo.GetDeviceContext
as they now both receive types as arguments.The main caveat of this approach is that now declaring a static class with a
const ID
field is no longer optional. Since the approach relies on type metadata, the compiler cannot enforce the compliance of device types with this rule at compile-time. This is probably minor as any errors or inconsistencies will immediately throw errors on any test. The most significant impact will be refactoring the name of this field in the long-term, which would have to be done with care.Fixes #116