Current filter:
                                You should refresh the page.
                                  • Consider the following class:

                                    [C#]
                                    class MyClass { private readonly Version m_version1; private readonly Version m_version2; public MyClass(Version version1, Version version2) { m_version1 = version1 ?? throw new ArgumentNullException(nameof(version1), $"{nameof(version1)} is null."); m_version2 = version2; } }

                                    If invoking the "Add Contract->Throw Exceptions Contract" in the constructor the following code is generated:

                                    [C#]
                                    public MyClass(Version version1, Version version2) { if (version1 == null) { throw new ArgumentNullException(nameof(version1), $"{nameof(version1)} is null."); } if (version2 == null) { throw new ArgumentNullException(nameof(version2), $"{nameof(version2)} is null."); } m_version1 = version1 ?? throw new ArgumentNullException(nameof(version1), $"{nameof(version1)} is null."); m_version2 = version2; }

                                    There is a redundant null check for version1 now . Expected the following code:

                                    [C#]
                                    public MyClass(Version version1, Version version2) { if (version2 == null) { throw new ArgumentNullException(nameof(version2), $"{nameof(version2)} is null."); } m_version1 = version1 ?? throw new ArgumentNullException(nameof(version1), $"{nameof(version1)} is null."); m_version2 = version2; }

                                    or possibly the more compact (should probably be controllable by some option in that case):

                                    [C#]
                                    public MyClass(Version version1, Version version2) { m_version1 = version1 ?? throw new ArgumentNullException(nameof(version1), $"{nameof(version1)} is null."); m_version2 = version2 ?? throw new ArgumentNullException(nameof(version2), $"{nameof(version2)} is null."); }
                                • George K (DevExpress) 12.01.2017

                                  Hi Peter,
                                  Thanks for the code snippets.
                                  We are working on this issue now and will notify you when we have any results.

                                1 Solution

                                Creation Date Importance Sort by

                                Fixed:


                                Additional information:

                                Hi Peter,

                                We have fixed the issue with adding a redundant 'null' check when a throw expression is used. As for supporting throw expressions for a generated 'null' check in the 'Throw Exceptions Contract' code provider, this requires more changes in the current architecture of this provider. We have added this task to our backlog and will consider implementing it in future updates. We will notify you of our progress in the context of this ticket.