[API proposal] Attribute for passing caller identity implicitly · Issue #4984 · dotnet/csharplang (original) (raw)
Navigation Menu
- GitHub Copilot Write better code with AI
- GitHub Models New Manage and compare prompts
- GitHub Advanced Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
Rationale
Number of libraries, including the new minimal ASP.NET host, use Assembly.GetCallingAssembly()
for convenience. Assembly.GetCallingAssembly()
is slow and unreliable API, and also not compatible with AOT technologies (e.g. dotnet/runtime#53825). We need a fast, reliable and AOT-friendly replacement of Assembly.GetCallingAssembly()
.
Proposal
namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] public sealed class CallerIdentityAttribute : Attribute { public CallerIdentityAttribute(); } }
This attribute can be applied to parameters of type System.Reflection.Assembly
, System.Reflection.Type
, System.Reflection.MethodBase
. When the C# compiler sees parameter tagged with this attribute, it will provide default value for it, according to the caller context:
System.Reflection.Assembly
:typeof(containing_type).Assembly
System.Reflection.Type
:typeof(containing_type)
System.Reflection.MethodBase
:MethodBase.GetMethodFromHandle(ldtoken containing_method)