Type placeholder #4768
Replies: 3 comments 6 replies
-
Sounds like you want semantic types, which you could do with a source generator. Have it trigger on an attribute like [assembly: SemanticType("ParamType1", typeof(int), Visibility.Public)]
[assembly: SemanticType("ParamType2", typeof(int), Visibility.Public)]
[assembly: SemanticType("ReturnType", typeof(int), Visibility.Public)]
public class Program
{
// With the generated types, attempting to call this method with the arguments reversed will error like you want.
public static ReturnType Method(ParamType1 param1, ParamType2 param2)
{
return new ReturnType(param1.Value + param2.Value);
}
} |
Beta Was this translation helpful? Give feedback.
-
Why not extend the existing |
Beta Was this translation helpful? Give feedback.
-
It will really useful for EF too (and Linq in general). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Background
In C/C++ you can use the typedef syntax, in many DBMS there are the user defined data types.
C# needs a similar functionality to permit code being more expressive, readable and secure.
Proposal
This proposal is about the new keywork "placeholder" and this new syntax:
that permits to add a real new type based on other types on the project.
Visibility
Scope
The scopes of the defined user type will be: global, namespace or class
based on the position of the declaration
Beta Was this translation helpful? Give feedback.
All reactions