-
Notifications
You must be signed in to change notification settings - Fork 21
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
Allow use
bindings in class scope with primary constructor
#561
Comments
While I like the idea of an automatic
This is a nice idea, and I like it in general, but we'd need to nail down some specifics before I'd feel comfortable giving it a 👍. |
@rmunn Thanks for reading the proposal and for your thoughtful response.
|
Duplicate of #312 which was rejected |
Allow
use
bindings in class scope with primary constructorOften, you may find yourself creating an object type that owns some disposable resource. In turn, you make your type disposable as well:
This ends up being a lot of boilerplate code that does not add much value. I propose we enable
use
bindings at the class level when there is a primary constructor, so the above could be written thusly:This syntax would:
IDisposable
interface.IDisposable.Dispose
that in turn calls dispose on all instances bound with class-leveluse
bindings in reverse order that they are declared.For instance, this:
would cause the compiler to emit the equivalent to:
use
-bound values are disposed in the opposite order that they are declared because they may have dependencies on previously-declared values.Pros and Cons
The advantages of making this adjustment to F# is:
The disadvantages of making this adjustment to F# are:
The
use
binding is already used for this purpose within functions and methods, so I believe this is a natural extension of that syntax. It is currently a compiler error to use it at the class level, so I do not believe there is any chance of this change breaking existing code.Open Questions
use
bindings are used at the class level, would there be any way to add code to the destructor? What would the syntax be?Affadavit (must be submitted)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: