-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Proposal]: Re-rename to Roles and Extensions #8431
Comments
I get the argument, and I could agree it’s better than “implicit/explicit” extension, but I can’t shake the feeling that “role” is weird. Because an explicit extension/role is still conceptually an extension of the specified type, just one you only use in specific situations - a proxy type of sorts. I don’t know; Just my $0.02. |
Just my 2 cents: if we want to drop implicit/explicit, would "extension type" not be an option for roles? I agree that "role" sounds weird. To me an explicit extension (a role) is really just a type. You treat it exactly as if it were an actual type in code (you use it to declare parameters, locals, can cast to it, etc.). It's just that it's specifically also an extension, not a "real" type. So to me "extension type" seems intuitive in that sense, more than "role". With the latter you get into "what is a role", "what does a role mean", etc., whereas with the former, people will just look at it as "oh ok, it's just a type I can declare an use, cool". |
I suggest we use "extension types" instead of "extensions" for implicit extensions. I think we will want to distinguish these from extension methods and also discuss the two in combination. |
One thing I kind of liked about the |
With the name |
To me, it's the other way. |
I imagine C# could fake it by emitting an unspeakable function name to IL and mapping it to the declared name for source code. Though it would be better if the CLR would add extension/role types to the type system. |
Just happen to see this was changed into role so pardon me for duplicate I am not so sure about current use case of I think Suppose we have public class Person
{
public DateTimeOffset birthDay;
}
public extension PersonExt for Person
{
public TimeSpan Age => DateTimeOffset.Now - birthDay; // everyone has age
}
public role Adult for Person // not everyone is adult
{
public static bool operator is(Person person) => person.Age.TotalYears >= 18;
public bool HasJob => false;
public bool Occupation => "College Student";
}
////
Person person0 = LoadFromDB(pid0);
if(person0 is Adult adult0) // check with operator is
Console.WriteLine(adult0.Occupation);
var adult1 = (Adult)LoadFromDB(pid1) // null if operator is return false Alternative syntax might be public role Adult for Person when (Age.TotalYears >= 18)
{
public bool HasJob => false;
public bool Occupation => "College Student";
} |
Re-rename to Roles and Extensions
This has been moved to https://github.com/dotnet/csharplang/blob/main/meetings/working-groups/extensions/rename-to-roles-and-extensions.md.
The text was updated successfully, but these errors were encountered: