-
-
Notifications
You must be signed in to change notification settings - Fork 413
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
Issues with Some.cs #13
Comments
- Some silly mistakes slipped through the net with checkin the Value property of Some<T> - Thanks to @tejacques for pointing them out! #13
Yep, some silly mistakes there. I've taken a different approach to fixing it: public T Value =>
CheckInitialised(value);
public static implicit operator T(Some<T> value) =>
value.Value;
public override string ToString() =>
Value.ToString();
public override int GetHashCode() =>
Value.GetHashCode();
public override bool Equals(object obj) =>
Value.Equals(obj); It puts slightly more burden on the
It's not the CLR, it's the C# compiler. It could easily call the same series of op-codes that it does for classes. It is however (like you say) an optimisation. I believe the C# team are discussing default constructors for the final C# 6. So we'll see how that goes. Until then I do discuss this on the project home page, and explain its limitations. I think only using Thanks for the heads up on the bugs! |
No problem -- I like the way you handled everything, I think that makes it work out nicely. Closing this issue now. |
format Exception to display full details
I think two changes should be made to Some.cs
First change: The overrides which call CheckInitialized should call their methods on the return value of CheckInitialized, rather than the value they pass in:
Should be
Reason:
If
Value
is not initialized it could have another exception thrown (such as NPE) because it's calling a method onValue
before checking whetherValue
is initialized.Second change: It's not enough to only check (and throw) in the default constructor because the CLR will not call the default constructor on arrays of structs.
Example:
Reason:
For performance reasons, the CLR will not call the default constructor on struct arrays. It will only zero out the memory associated with them. You'll have to raise an error in the getter property to catch this case.
The text was updated successfully, but these errors were encountered: