question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

infoof / propertyof / methodof (and reflection objects in attributes?)

See original GitHub issue

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 and methodof 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)

class Message
{
    [NotifyChanges(propertyof(Message.Followers))]
    public string Content { get; set; }

    public IEnumerable<IIdentity> Followers { get; set; }
}

class UserProfile
{
    [ReadableBy(propertyof(UserProfile.User), propertyof(User.Friends))]
    public string PhoneNumber { get; set; }

    public IIdentity User { get; set; }
}

class Group
{
    [WriteableBy(propertyof(Group.Members))]
    public string Title { get; set; }

    public IEnumerable<IIdentity> Members { get; set; }
}

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

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
MadsTorgersencommented, Aug 15, 2016

We consider nameof to be our best attempt at addressing the majority of scenarios for this feature. It doesn’t get all of them, but on the other hand it can be used to get most of the rest through reflection API calls, and it is orders of magnitude less complex as a language feature.

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.

1reaction
svickcommented, Feb 11, 2016

#1653 proposes the same feature, only with different syntax. I think one of these two proposals should be closed as duplicate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attributes and reflection
Attributes provide a powerful method of associating metadata, or declarative information, with code (assemblies, types, methods, properties, and ...
Read more >
PropertyInfo.Attributes Property (System.Reflection)
The Attributes property returns the attributes associated with the property represented by this PropertyInfo object. The attributes are primarily modifiers ...
Read more >
Reflection - get attribute name and value on property
In my main method, I'm using reflection and wish to get key value pair of each attribute for each property. So in this...
Read more >
Attributes and Reflection - C# in Simple Terms
Reflection is a technique that allows us to gather data about an object, rather than the data within the object itself. This information...
Read more >
Reading Attributes with the Reflection API - Manual
To access attributes from classes, methods, functions, parameters, properties and class constants, the Reflection API provides the method getAttributes() on ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found