You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Soon with C# 12, this will be extended to mean essentially arbitrary aliasing for even things like tuples. It has a few limitations still, that I'd like to propose we resolve:
No local aliasing
No generic types
No referencing the alias from outside the file
Basic feature
We could allow aliasing ourselves using a similar syntax, but maybe a better keyword:
typeFoo = int32;
An alternative keyword I thought of was alias.
We could also allow aliasing in any scope, just like we allow our other features, meaning it does not have to be a top-level element, like in C#.
Generic aliasing
C# does not allow for generic aliasing, meaning the following is not legal:
using MyList<T>= System.Collection.Generic.List<T>;
We could allow this, but there is one caveat: This syntax would also need to introduce a generic constraint list, once we introduce them in the language. Example:
This might be a controversial one. C# does not allow type aliases to be visible outside of the file-local scope. This is somewhat understandable, but becomes annoying in places where we deal with lots of structural types and need to alias big types in every file. We could allow the alias to have a visibility, just like other language elements, meaning private by default, explicit internal or public.
Examples:
// Private to filetypeFoo= int32;// Private to projectinternaltypeBar=OneOf<int32,string>;// Accessible from outsidepublictypeMessage=OneOf<int32,string,List<(int Sequence,string Tag, Contracts.MessageBody)>>;
Considerations
This feature would obviously be bounded by the language in a sense, that a C# project referencing a Draco project won't be able to see this alias, unless some aliasing mechanism can be injected in metadata that would allow for this.
The text was updated successfully, but these errors were encountered:
C# allows for type aliasing using the syntax
Soon with C# 12, this will be extended to mean essentially arbitrary aliasing for even things like tuples. It has a few limitations still, that I'd like to propose we resolve:
Basic feature
We could allow aliasing ourselves using a similar syntax, but maybe a better keyword:
An alternative keyword I thought of was
alias
.We could also allow aliasing in any scope, just like we allow our other features, meaning it does not have to be a top-level element, like in C#.
Generic aliasing
C# does not allow for generic aliasing, meaning the following is not legal:
We could allow this, but there is one caveat: This syntax would also need to introduce a generic constraint list, once we introduce them in the language. Example:
Aliasing with visibility
This might be a controversial one. C# does not allow type aliases to be visible outside of the file-local scope. This is somewhat understandable, but becomes annoying in places where we deal with lots of structural types and need to alias big types in every file. We could allow the alias to have a visibility, just like other language elements, meaning private by default, explicit internal or public.
Examples:
Considerations
This feature would obviously be bounded by the language in a sense, that a C# project referencing a Draco project won't be able to see this alias, unless some aliasing mechanism can be injected in metadata that would allow for this.
The text was updated successfully, but these errors were encountered: