dotnet / dotnet/csharplang

[Proposal]: Caller info attribute for passing caller identity implicitly

Open
#9,018 0 comments 0 reactions 1 assignee Claimed by @jaredpar View on GitHub
Proposal champion
Dominant language
C#
Stars
12.7k
Forks
1.1k
Avg merge
11h 1m
Merged PRs (30d)
3

Description

# Caller info attribute for passing caller identity implicitly

* Specification:
* Discussion: https://github.com/dotnet/csharplang/discussions/9017

## Summary
[summary]: #summary

```cs
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)`

## Design meetings

* https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-09-22.md#calleridentityattribute
* https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-01-24.md#attribute-for-passing-caller-identity-implicitly

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.