Add typedef
-like functionality to simplify type aliasing across namespaces
#9334
Unanswered
XmmShp
asked this question in
Language Ideas
Replies: 2 comments 1 reply
-
I think this will be covered by roles. #5496 |
Beta Was this translation helpful? Give feedback.
0 replies
-
re: Conceptual Separation, check out https://github.com/SteveDunn/Vogen. Looks like a solution that is gaining some broader interest.
Why don't we fix that? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Statement:
Currently, C# provides limited support for type aliasing through the
using
directive (e.g.,using MyType = SomeNamespace.SomeType;
). However, this approach has several limitations:using
are scoped to a single file unless combined withglobal using
(introduced in C# 10, but it doesn't support generic type). This makes it cumbersome to define and maintain aliases across large projects.Response
andResult
might be structurally identical but conceptually distinct. A developer-friendly way to alias these types would improve code readability and maintainability.Proposed Solution:
Introduce a new
typedef
-like feature inspired by TypeScript'stype
keyword. This feature would allow developers to define type aliases that:Example Use Case:
Suppose we have two classes,
Response
andResult
, which are structurally identical but conceptually distinct:Currently, if we want to treat these as interchangeable in certain contexts, we must manually manage conversions or use verbose type names. With the proposed
typedef
-like feature, we could define:This would allow developers to use
BusinessLogic.Models.Result
interchangeably withApi.Models.Response
while maintaining conceptual clarity.Benefits:
Implementation Considerations:
type
keyword or use a new keyword liketypedef
:global typedef
keyword to define aliases that are globally available.Example:
Alternatives:
using
directives, but this requires repeating the alias in every file or usingglobal using
.In discussion #1300 , someone has told about this issue, but it looks that his usage is not so specific.
Beta Was this translation helpful? Give feedback.
All reactions