Closed vvdb-architecture closed 7 months ago
Yes, the pragma restore of 8616 must happens after the ctor. Not after the _baseUrl field
I think a better solution is to generate
public string BaseUrl
{
get { return _baseUrl; }
[System.Diagnostics.CodeAnalysis.MemberNotNull(nameof(_baseUrl))]
set
{
_baseUrl = value;
if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/"))
_baseUrl += '/';
}
}
To let the compiler null analysis know that the property setter sets the field _baseUrl.
I think a better solution is to generate
public string BaseUrl { get { return _baseUrl; } [System.Diagnostics.CodeAnalysis.MemberNotNull(nameof(_baseUrl))] set { _baseUrl = value; if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) _baseUrl += '/'; } }
To let the compiler null analysis know that the property setter sets the field _baseUrl.
In my netstandard2.0 project, this gives: 'MemberNotNullAttribute' is inaccessible due to its protection level.
this is completely fucked in 14.0.3
Error CS0234 The type or namespace name 'MemberNotNullAttribute' does not exist in the namespace 'System.Diagnostics.CodeAnalysis' (are you missing an assembly reference?)
You should be able to reference the Nullable
package as a workaround until this is fixed.
14.0.3 results in the same error as @rwb196884 reducing to 14.0.2 fixes
Yes, the pragma restore of 8616 must happens after the ctor. Not after the _baseUrl field
Or simply do this.
We're also getting the error again in 14.0.3.
I also get this error in 14.0.3, on 14.0.2 it works as expected.
this is completely fucked in 14.0.3
Error CS0234 The type or namespace name 'MemberNotNullAttribute' does not exist in the namespace 'System.Diagnostics.CodeAnalysis' (are you missing an assembly reference?)
When compiling with 14.0.1, the generated C# sdk now has the following warning:
That's because even though the constructor assignes
BaseUrl
:... the compiler is unable to detect that the
_baseUrl
field is in fact initialized through this property.The way to get rid of the warning is to assign the field directly:
Also, the warnings reported in issue https://github.com/RicoSuter/NSwag/issues/4467 are still there.