-
Notifications
You must be signed in to change notification settings - Fork 4k
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
infoof / propertyof / methodof (and reflection objects in attributes?) #128
Comments
Couldn't you use nameof() feature of C# 6 to achieve the same? |
What @thebigb is asking for is something to get the |
Of course it gives you name. Do you need more? In the example above the consumer of the attributes could use Reflection to get the *Infos corresponding to the names. |
I think this sums it up:
|
nameof provides compile-time resolution and refactoring benefits. The only missing piece is retrieving the runtime representation of the member (PropertyInfo). Which is no magic. Just invoke TypeInfo.GetDeclaredProperty(name). |
I'm curious as to what kind of IL would be generated in each of these cases. At least with a hypothetical |
#1653 proposes the same feature, only with different syntax. I think one of these two proposals should be closed as duplicate. |
We consider There's also something good about keeping reflection (mostly) out of the language. You opt into it very explicitly through use of APIs. We don't expect to go any further in this direction for the foreseeable future. |
infoof
is a feature that according to Eric already has been discussed internally already[1], but requires some delicacy when implemented.I think we all understand the basic use case, that is to replace dynamic / magic reflection with a statically typed variant (with possible compile-time resolution and refactoring benefits?). Here's another idea:
When designing (theoretically) infinitely scalable systems, caching is a first-order necessity. Invalidating cache in a scalable design, however, can be quite a challenge[2]. One could manually make a dependency map to ease the pain. But who is going to do that? And who is going to maintain it? By using attributes one could quite well define dependencies between entity types, but how about we kick it up a notch and define dependencies between properties of entities? With
propertyof
andmethodof
operators (and allowing the return values to be stored in attributes) this could be achieved.Consider the following examples:
(note that these are just a quick examples, that don't necessarily bear any use)
Dependency mapping is a very specific use case, but you can take this into a wider perspective. The feature can be valuable to improve meta-description of your code and data entities, and I believe this could contribute to the meta-programming theme.
[1] http://blogs.msdn.com/b/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx
[2] https://stackoverflow.com/questions/1188587/cache-invalidation-is-there-a-general-solution
The text was updated successfully, but these errors were encountered: