Replies: 7 comments 31 replies
-
Can we make |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Looks like the primary constructor design can neatly simply dependency injection scenario: public class MyService(FooService foo, BarService bar, ...)
{
public async Task DoSomething()
{
await foo.Blabla();
...
}
} The only tiny missing thing is to mark the captured field |
Beta Was this translation helpful? Give feedback.
-
I'm not sure I understood the difference so does this mean that |
Beta Was this translation helpful? Give feedback.
-
The changes to extensions here remind me a lot of Scala implicit classes, which were introduced in Scala 2.10 and intended to accomplish the same thing. The way they worked was that as long as you had the implicit class in scope you could then invoke members of that implicit class on the underlying type and the compiler would implicitly convert the underlying type into the implicit type: // given
object Extensions {
implicit class IntExtensions(x: Int) {
def doubled() = x * 2
}
}
// then
import Extensions._
val r = 5.doubled
// and the compiler would emit
val r = IntExtensions.apply(5).doubled() That mental model translates to extensions proposed here: // given
implicit extension IntExtensions for int {
int Doubled { get => this * 2; }
}
// then
var r = 5.Doubled;
// and the compiler would emit something like
var r = ((IntExtensions) 5).Doubled; The "cast" to the extension type occurs implicitly for an // given
explicit extension IntExtensions for int {
int Doubled { get => this * 2; }
}
// not legal
var r = 5.Doubled;
// legal
IntExtensions ext = (IntExtensions) 5;
var r = ext.Doubled; I'm hoping that the conversation around // given
explicit extension NonZero<T> for T where T : INumberBase<T> {
// spaghetti at the wall syntax
public static bool operator is(T number) {
return !T.IsZero(number);
}
public void Tada() { }
}
// then
var x = 1;
if (x is NonZero<int> nz) {
nz.Tada();
} |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Do you guys have some examples of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
https://github.com/dotnet/csharplang/blob/main/meetings/2023/LDM-2023-02-22.md
Agenda
Beta Was this translation helpful? Give feedback.
All reactions