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
It would be very useful (especially for MVC/EF projects) to be able to define types as being the same type as something else (eg. a field or property) rather than directly referring to the type by name. I will give an example: -
In EF, if you have a large number of data model classes, they would typically have primary key ID fields of different types. They may be byte, int16, int32, int64, guid etc. When you create a foreign key field or when you create a field in an MVC model class to use data from or search the data model field, you have to look up the correct type. An even more significant problem is that if you want to change the type, there is no automatic method for updating all the various properties and fields in other classes/structs which should have the same type as the main one.
I would like to propose a new compiler keyword, such as sametypeas (c#) or SameTypeAs (VB.NET) to solve this problem. An example of this would be (in VB.NET as that is my primary language): -
Class Customer
Public Property ID As Long
...
End Class
Class [Order]
Public Property ID As Long
Public Property CustomerID As SameTypeAs([Customer].[ID])
...
End Class
Ideally the compiler should be capable of using this keyword across assembly boundaries into referenced assemblies - not just within the current assembly.
The text was updated successfully, but these errors were encountered:
I think you'd run into some of the same issues as mentioned in #1042. If Customer.ID were also declared As SameTypeAs([Order].[CustomerID]) then there would be a cycle in the compiler's static analysis.
I'd have thought that wouldn't be a major issue to resolve - you can always throw a compiler error if a cycle is detected. Alternatively, make it illegal to use SameTypeAs on any members in the local assembly which are declared using SameTypeAs - can't see why you'd want to do that anyway since you'd presumably want them all rooted on the same member.
It would be very useful (especially for MVC/EF projects) to be able to define types as being the same type as something else (eg. a field or property) rather than directly referring to the type by name. I will give an example: -
In EF, if you have a large number of data model classes, they would typically have primary key ID fields of different types. They may be byte, int16, int32, int64, guid etc. When you create a foreign key field or when you create a field in an MVC model class to use data from or search the data model field, you have to look up the correct type. An even more significant problem is that if you want to change the type, there is no automatic method for updating all the various properties and fields in other classes/structs which should have the same type as the main one.
I would like to propose a new compiler keyword, such as sametypeas (c#) or SameTypeAs (VB.NET) to solve this problem. An example of this would be (in VB.NET as that is my primary language): -
Class Customer
Public Property ID As Long
...
End Class
Class [Order]
Public Property ID As Long
Public Property CustomerID As SameTypeAs([Customer].[ID])
...
End Class
Ideally the compiler should be capable of using this keyword across assembly boundaries into referenced assemblies - not just within the current assembly.
The text was updated successfully, but these errors were encountered: