-
-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use nullable reference types throughout CSLA codebase #1233
Comments
@rockfordlhotka |
I'd love to have you do this! It'll be CSLA 9 thing, as I'm sure there'll be breaking changes. |
@rockfordlhotka I'll link you here from now on for questions regarding the nullable context :-) csla/Source/Csla/Core/FieldManager/FieldData.cs Lines 28 to 42 in 579c84d
Is the empty ctor only there for the |
MobileFormatter does require an empty default ctor. Whether that is explicit or implicit, it is required for all types that implement |
In that case I'll mark it as Obsolete. MobileFormatter can still use it but it's not usable any more at compile time :-) |
And should I really add now everywhere a null argument check where it's currently just assumed to be not null? 😅🤔 |
That seems wise doesn't it? |
I concur with @rockfordlhotka. If a parameter is a NRT, someone could still pass in |
Hey - this is now part of the permanent record!! @JasonBock agrees with me!! 😁 |
@rockfordlhotka don't make me do it.... |
@rockfordlhotka How should we handle csla/Source/Csla/ApplicationContext.cs Lines 143 to 147 in 0f46935
I personally don't like to set something null when I just can assign a new instance to avoid that. At the cost of memory consumption obviously.But - and I think that's the biggest downside on allwoing null in such cases - we have to mark ClientContext as nullable which means every code says "Hey! This could be null here. Please check that" eventhough we know that won't ever be the case. But that's not expressable by the current annotations as far as I am aware.
|
@StefanOssendorf that is interesting. I suspect one was written (or updated) after the other. I think the current best approach is to use the Globalization namespace, but I'm not sure. |
Is the type |
csla/Source/Csla/Server/ObjectFactory.cs Lines 62 to 75 in e035ad7
Is it a bug that the |
Yes. That whole thing exists as a fallback for an edge case I suspect no one actually uses, but for completeness it should be made to work. |
Yeah. But shouldn't the fallback also tries to invoke |
Yes. I'm not actually sure what that was for or where it came from. Looks like a duplicate of |
Yes, that is what I'm saying. It should be made to work - which means trying to invoke both. |
For Also, I do like empty collections over |
I split this into its own issue (#4266) so we can discuss better. |
Is it intended that an aggregate exception populates an exception but a DataPortalException resumes the execution flow? 🤔 csla/Source/Csla/DataPortalT.cs Lines 119 to 136 in e035ad7
|
I am pretty sure this is intended. If a |
But that's my question. A |
I think the code is correct as-is. The |
Yep. You are totally right. I thought the |
Another look please :-) csla/Source/Csla/DynamicListBase.cs Lines 266 to 279 in 6789bb5
IMHO this is bad and a bug. I don't know if this base class is really in use. async void for non event handler should be banned ^^'. If I read this right this will not bubble up any exceptions to the user during a save.
Edit: csla/Source/Csla/DynamicListBase.cs Line 346 in 6789bb5
|
I don't disagree in principal, but iirc this is required by Windows Forms data binding so I don't know that it can be fixed. Hmm, maybe it can - is there also a |
Csla nullable aware (WIP) Also fixing affected places Fixes #1233
Hey everyone, I need some opinions on how to tackle NRTs :) I've added NRT to the I have (currently) two major problems/concerns. A) Annotating our generic mobile base classes. The declaration of that type must be And here's the problem: public T? GetValue<T>(string name)
{
var value = _values[name].Value;
return value != null ? Utilities.CoerceValue<T?>(value.GetType(), null, value) : (T?)value;
} handles And now I'm stuck with I currently see these options to "solve" that problem:
B) protected P GetRequiredProperty<P>(PropertyInfo<P> propertyInfo)
{
if (propertyInfo is null)
{
throw new ArgumentNullException(nameof(propertyInfo));
}
if (propertyInfo.RelationshipType.HasFlag(RelationshipTypes.LazyLoad))
{
throw new NotSupportedException("Lazy load is not allowed by an required property call. Use the normal GetProperty method.");
}
ThrowIfNotAllowedToRead();
return ReadRequiredProperty<P>(propertyInfo);
// Dummy to show the intention
static void ThrowIfNotAllowedToRead()
{
throw new NotSupportedException();
}
}
protected P ReadRequiredProperty<P>(IPropertyInfo propertyInfo)
{
// Throw if property can not be read
// return property value
} I'm thinking about adding methods like that where I do not handle any An example would be: public static readonly PropertyInfo<string> MyProperty = ...
public string My {
get => GetProperty<string>(MyProperty)!; // <-- !-operator to suppress the (wrong) null annotation
set => SetProperty<string>(MyProperty, value);
} I hope this makes any sense to you guys at all. If not please just ask and I try to clarify as good as I can. |
The question, really - is possibility of null in this place avoidable, because of other reasons, that way slap There is third option - you also can silence warnings using
that way you preserve existing runtime behaviour where you don't have runtime penalty on checking for null and throw NRE in rare cases but in debug builds you can catch that. Also compiler would be happy You maybe can utilize Line 153 in a1cebe0
More about it here https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/nullable-analysis#postconditions-maybenull-and-notnull |
The |
@rockfordlhotka |
Is your feature request related to a problem? Please describe.
C#8 adds nullable reference types. Not only will CSLA need to support this, but it should also annotate its members with not just
?
, but with the new nullable attributes.Describe the solution you'd like
NRT support throughout CSLA.
Describe alternatives you've considered
Nothing :)
Additional context
Use this reference for details/information.
The text was updated successfully, but these errors were encountered: