Add casting operators for int? and long?#35
Merged
Krusen merged 4 commits intoKrusen:masterfrom Feb 11, 2019
carlosjdelgado:add-nullable-bnumber-castings
Merged
Add casting operators for int? and long?#35Krusen merged 4 commits intoKrusen:masterfrom carlosjdelgado:add-nullable-bnumber-castings
Krusen merged 4 commits intoKrusen:masterfrom
carlosjdelgado:add-nullable-bnumber-castings
Conversation
With this change I try to fix the following case:
```
return new KrpcQuery
{
Id = queryDictionary.Get<BString>("id")?.ToString(),
InfoHash = queryDictionary.Get<BString>("info_hash")?.ToString(),
Target = queryDictionary.Get<BString>("target")?.ToString(),
ImpliedPort = queryDictionary.Get<BNumber>("implied_port"), // ImpliedPort is an int?
Token = queryDictionary.Get<BString>("token")?.ToString()
};
```
This throws InvalidCastException, when try to get "implied_port" key, I want to get null if does not exist in the dictionary.
Owner
|
Thanks for the PR. Your tests doesn't actually test your added code but instead tests casting from If you can change the tests to the following I can get this merged :) [Fact]
public void CanCastToNullableInt_WhenNull()
{
BNumber bnumber = null;
var number = (int?) bnumber;
number.Should().BeNull();
}
[Fact]
public void CanCastToNullableLong_WhenNull()
{
BNumber bnumber = null;
var number = (long?) bnumber;
number.Should().BeNull();
}
[Fact]
public void CanCastToNullableInt_WhenNotNull()
{
var bnumber = new BNumber(42);
var number = (int?) bnumber;
number.Should().Be(42);
}
[Fact]
public void CanCastToNullableLong_WhenNotNull()
{
var bnumber = new BNumber(42);
var number = (long?) bnumber;
number.Should().Be(42);
} |
Contributor
Author
|
What a mistake 😌, I'll fix it as soon as possible, thanks! |
Contributor
Author
|
@Krusen I had fixed tests covering all cases (casting from and to int, long, nullable int and nullable long) Will it be possible to have a new nuget version with these changes? |
Owner
|
Thanks! Version 2.3.0 has been published. |
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.
With this change I try to fix the following case:
This throws InvalidCastException, when try to get "implied_port" key, I want to get null if does not exist in the dictionary.