Add TryGetValue to RowRef{T}, SubrowRef{T}#129
Merged
Conversation
Contributor
|
Is there a reason why we should have this interface? This feels more like a potential footgun rather than a nice-to-have. |
Contributor
Author
|
I currently have this as extension method and am using this to return early. public bool CanTryOn(ItemHandle item)
{
if (!TryGetItem(item, out var itemRow))
return false;
// not equippable, Waist or SoulCrystal => false
if (itemRow.EquipSlotCategory.RowId is 0 or 6 or 17)
return false;
// any OffHand that's not a Shield => false
if (itemRow.EquipSlotCategory.RowId is 2 && itemRow.FilterGroup != (int)ItemFilterGroup.Shield)
return false;
if (!_playerState.IsLoaded)
return false;
var race = _playerState.Race.RowId;
if (race == 0)
return false;
if (!itemRow.EquipRestriction.TryGetRow(out var equipRaceCategoryRow)) // <--- here
return false;
if (!equipRaceCategoryRow.Races[(int)race - 1])
return false;
return _playerState.Sex switch
{
Sex.Female => equipRaceCategoryRow.Female,
Sex.Male => equipRaceCategoryRow.Male,
_ => false
};
}Though I coded it a bit differently: extension<T>(RowRef<T> rowRef) where T : struct, IExcelRow<T>
{
public bool TryGetRow(out T row)
{
if (rowRef.IsValid)
{
row = rowRef.Value;
return true;
}
row = default;
return false;
}
}If the user is disregarding the return value when using the TryGet pattern, that's entirely on them. It's the same as not checking HasValue. I also don't mind to continue using my extension method (rewritten to the one PRd), if I have to. |
Owner
|
looks good to me, not sure where the footgun is here |
Contributor
|
I suppose so, its fine if someone needs that exact interface. |
NotAdam
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Just for supporting the TryGet pattern in the typed RowRef/SubrowRef.
The untyped RowRef already has it.
CC: @WorkingRobot