Skip to content
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: Indirect typing #7715

Closed
wizzardmr42 opened this issue Dec 28, 2015 · 3 comments
Closed

Proposal: Indirect typing #7715

wizzardmr42 opened this issue Dec 28, 2015 · 3 comments
Labels
Area-Language Design Resolution-Duplicate The described behavior is tracked in another issue

Comments

@wizzardmr42
Copy link

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.

@bondsbw
Copy link

bondsbw commented Dec 28, 2015

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.

@wizzardmr42
Copy link
Author

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.

@gafter
Copy link
Member

gafter commented Dec 29, 2015

Dup of #3281

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Language Design Resolution-Duplicate The described behavior is tracked in another issue
Projects
None yet
Development

No branches or pull requests

3 participants