Skip to content

Conversation

@scamille
Copy link
Member

This requires reference types that can be null to be annotated by a ? operator, similar to value types.

This gives the advantage that the compiler can warn against any nullreference exceptions, of which this commits elimits a few.

To make the underlying protocol implementation not any more complicated and to eliminate existing problems, and to give more precise error reporting, I replaced some return null statements with explicit Exceptions. This lead to the assumption that those core protocol functions always return non-null objects if they do not throw, making the PLC code simpler.

Adjust some NotConnected tests to look for explicit PlcException instead of NullReferenceException.

@scamille
Copy link
Member Author

I assume this is the motivation for #296 ? I did not realize that this did not work with Visual Studio 2017 - haven't used it in a long time.

But great to see that you seems interesting in potentially supporting it. I have come to really like nullable support for all my projects even for .NET Framework things. It really helps detect NullReference exceptions and to be more explicit about which variables are nullable and which are not.
And I think that would also help S7.NetPlus both internally and for people using the library.

@mycroes
Copy link
Member

mycroes commented Aug 31, 2020

Hi @scamille,

Yes this was motivation for #296, which is superseded by #302. Can you update your PR and see if it works now? I will definitely accept this PR; the only reason I personally see to avoid nullable reference types is legacy codebases.

@scamille
Copy link
Member Author

Adjusting S7NetPlus to have nullable annotations should not affect any user of the library, unless nullable support is enabled there as well. It is after all just a compiler-internal annotation, and does not change anything about the fact that reference type variable can still be null.

This requires reference types that can be null to be annotated by a ? operator, similar to value types.

This gives the advantage that the compiler can warn against any null dereference exceptions, of which this commits elimits a few.

To make the underlying protocol implementation not any more complicated and to eliminate existing problems, and not that precise error reporting, I replaced some return null statements with explicit Exceptions. This lead to the assumption that those core protocoll functions always return non-null objects if they do not throw, making the PLC code simpler.

Adjust some NotConnected tests to look for explicit PlcException instead of NullReferenceException.
@mycroes
Copy link
Member

mycroes commented Sep 1, 2020

HI @scamille, I understand how the feature works, I just meant that I wouldn't enable nullable reference types on a 10k+ lines codebase if there's no obvious reason to do so (or at least professionally, since I can't substantiate the investment with regards to the benefits). Nevertheless, I'm happy that you made this change, merging right away.

@mycroes mycroes merged commit 324ae95 into S7NetPlus:develop Sep 1, 2020
@scamille scamille deleted the fb-nullable branch September 6, 2020 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants