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

Missing discussion of allowed expressions for attribute constructor arguments #6428

Open
binki opened this issue Jul 12, 2018 — with docs.microsoft.com · 5 comments
Labels
doc-enhancement Improve the current content [org][type][category] dotnet/svc Pri1 High priority, do before Pri2 and Pri3

Comments

Copy link

binki commented Jul 12, 2018

I’m not sure exactly where this belongs. Perhaps it belongs in the Applying Attributes article instead. But it could also make sense here because the allowed constructor expressions limits the types of parameters one can meaningfully accept in an attribute’s constructor.

The expressions allowed as parameters to attributes are very limited. I think it includes constant expressions (notably including the useful nameof()) plus a at least one one exception typeof(TypeName) (if not other special expressions). It might also be worth discussing how CallerInformationAttribute can be applied to an attribute constructor’s parameters to get the name of the member the attribute is being applied to.

I expected this to be documented, but I can’t find the documentation for it. I looked in these places:

  1. Applying Attributes
  2. Writing Custom Attributes
  3. Retrieving Information Stored in Attributes
  4. “Attribute Parameters” in Attributes

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Copy link

phillijw commented Sep 9, 2019

It would also be nice to see some discussion of how I deal with dependency injection for these constructors. Perhaps it's not allowed at all?

@binki
Copy link
Author

binki commented Sep 9, 2019

@phillijw For these constructors, you mostly can do DI indirectly through passing in Types and making whatever is processing the attributes aware of your DI. For example, some DI systems themselves let you mark objects with attributes specifying arbitrary values such as names or priority levels so that your runtime code can select between alternative implementations. But attributes themselves are restricted to constants and Type. I do not think that discussion relates to the issue I filed and it might be beyond the scope of the documentation on attributes itself. Please consider opening another one if you want to explore that.

Thanks!

@tdykstra tdykstra added doc-enhancement Improve the current content [org][type][category] P1 labels Nov 18, 2019
@PRMerger8 PRMerger8 added the Pri2 label Jan 16, 2021
@dotnet-bot dotnet-bot added the won't fix Issues that were closed as part of automated backlog grooming label Jan 25, 2021
@dotnet-bot
Copy link
Contributor

This issue has been closed as part of the issue backlog grooming process outlined in #22351.

That automated process may have closed some issues that should be addressed. If you think this is one of them, reopen it with a comment explaining why. Tag the @dotnet/docs team for visibility.

@binki
Copy link
Author

binki commented Jan 25, 2021

@BillWagner This is still an issue.

@binki
Copy link
Author

binki commented Jan 25, 2021

@dotnet/docs @akoeplinger ^

@sharwell sharwell removed the won't fix Issues that were closed as part of automated backlog grooming label Jan 25, 2021
@sharwell sharwell reopened this Jan 25, 2021
@gewarren gewarren added Pri1 High priority, do before Pri2 and Pri3 and removed P1 Pri2 labels Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-enhancement Improve the current content [org][type][category] dotnet/svc Pri1 High priority, do before Pri2 and Pri3
Projects
None yet
Development

No branches or pull requests

10 participants