I have the following code:
var keyValuePairs = JsonSerializer.Deserialize<Dictionary<string, object>>(jsonbytes);
var claims = keyValuePairs.Select(kvp => new Claim(kvp.Key, kvp.Value.ToString()));
As you can see my ide shows me a Nullable warning.
I know that I have to check if a variable is null before using it to get rid of such a warning. But I don’t know how to do it with dynamic variables in a linq query..?
I hope someone can show me how I can avoid such a warning in this situation.
4
Answers
as pazcal said already i can use a ! after the object to escape such a warning. Many thanks for that hint.
Anyway, i've changed my function now to this:
I hope, that this is safe now :-)
Many thanks for your help.
The IDE gives you this warning as this variable might be
null
when it hits this line.If you are fully confident that this will never be the case, you can use the
!
to escape these warnings:If 1 of the properties might be
null
you can escape these:In your .csproj file, you will find like this
This
<Nullable>enable</Nullable>
field gonne be disable. I think this is your solution. But not safe one.How about this?