Replies: 61 comments 12 replies
-
I'm not sure I see a need for By supporting just
I do like the idea of having a |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to make the value lazy, so they are produced when need / used. |
Beta Was this translation helpful? Give feedback.
-
@AdamSpeight2008 I'm not sure that would work. From MSDN, "Caller Info values are emitted as literals into the Intermediate Language (IL) at compile time." That would prevent them from being lazily evaluated since they aren't evaluated at run time. |
Beta Was this translation helpful? Give feedback.
-
Completes the set, mostly. I could see some use for capturing the position of multiple calls to the same method nested in some other expression, but that might be pretty esoteric.
Yes. C# already supports My use cases would be covered if the only caller-info attributes were
Technically true, but it's possible that some of the work could be deferred until runtime. Specifically with |
Beta Was this translation helpful? Give feedback.
-
Do you mean So, right now we already have I think if we just added
I would think this wouldn't be desirable due to performance considerations. It also introduces different compile-time behavior between using the attributes directly and using the struct. Then again, it might not be possible to implement |
Beta Was this translation helpful? Give feedback.
-
Oops, you're right. None of the attributes cover the type at the moment.
I don't see why not. They're not as simple as expressions as pushing a string literal or an integer literal, but they're still relatively easy. It's two IL opcodes to derive the |
Beta Was this translation helpful? Give feedback.
-
@HaloFour |
Beta Was this translation helpful? Give feedback.
-
Yes, it would be a runtime call. The only way to avoid that would be to have those caller-info attributes applied to parameters of type Either way, this is a lot less overhead than what people are doing now to support getting this kind of information which is accepting a |
Beta Was this translation helpful? Give feedback.
-
Absolutely agree on that! :) Yes, this introduces a small amount of overhead, but significantly less than what's incurred now to get the same information. |
Beta Was this translation helpful? Give feedback.
-
Another possibility is to do something similar to what we do with strings literals. Have a embedded dictionary lookup table. |
Beta Was this translation helpful? Give feedback.
-
Building general purpose computing with CallerMemberName is extremely frustrating due to the lack of CallerTypeName, leads to all kinds of voodoo required to coerce types from somewhere that you can locate who someone is. |
Beta Was this translation helpful? Give feedback.
-
@scottdorman |
Beta Was this translation helpful? Give feedback.
-
@dotnetchris same here. Even just the fully qualified caller type name as a parameter attribute would solve a multitude of problems. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Basically I want more and more tools to be able to write programming to write my programming. |
Beta Was this translation helpful? Give feedback.
-
@CodeAngry - username checks out... |
Beta Was this translation helpful? Give feedback.
-
I wanted to post my note for this, especially "CallerMemberType" as a Type (and not a string). |
Beta Was this translation helpful? Give feedback.
-
This might be a whole other can of worms, but I think it would be extremely helpful if CallerMemberType could be used in generics as well. For example, you could have some function like this:
Then you could use it like so:
|
Beta Was this translation helpful? Give feedback.
-
Any information about CallerTypeName in .Net 6? |
Beta Was this translation helpful? Give feedback.
-
Related: #4984 |
Beta Was this translation helpful? Give feedback.
-
This really need some traction, as I keep coming back to needing this functionality when dealing with things like logging, or I'm working on "plugin-esque" applications. I keep ending up creating messy "hacks" to get the information I need to meet some specs, and if this proposal was implemented I probalbly would have saved tens, if not hundreds of hours of development and maintainence of convoluted reflection -based logic |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
I feel like multiple sources have been submitted for this over the past half decade |
Beta Was this translation helpful? Give feedback.
-
we are interested in CallerTypeNameAttribute too. Would be very nice for logging performancetracing etc |
Beta Was this translation helpful? Give feedback.
-
We are also interested in the CallerTypeName attribute, specifically for logging needs. Would be nice to know what the current state of this is |
Beta Was this translation helpful? Give feedback.
-
I like the idea of a CallerInfo class, it would make debugging universally easier because it is not restricted to one specific aspect like the other Caller attributes |
Beta Was this translation helpful? Give feedback.
-
CallerTypeName or CallerType would make things so much easier |
Beta Was this translation helpful? Give feedback.
-
Lets keep this up. |
Beta Was this translation helpful? Give feedback.
-
Turns out I too need |
Beta Was this translation helpful? Give feedback.
-
only |
Beta Was this translation helpful? Give feedback.
-
Copied from dotnet/roslyn#351
Problem:
The currently supported caller info attributes can only provide the name of the method, the name of the source file and the line number of the call in the source file. This is fine for scenarios such as simplifying implementations of
INotifyPropertyChanged
. However, if using these attributes for logging the amount of information available is quite limited.Solution:
Expand the number of supported caller info attributes to allow embedding additional diagnostic information. The following list is quite expansive to discuss/argue over the potential possibilities.
CallerColumnNumberAttribute: The column number of where the method is invoked.
CallerTypeNameAttribute: The simple name of the declaring type of the calling method.
CallerNamespaceAttribute: The namespace of the declaring type of the calling method.
CallerFullTypeNameAttribute: The full name of the declaring type of the calling method.
CallerTypeAttribute: The declaring type of the calling method. This is replaced by the compiler by
ldtoken
of the type followed by a call toType.GetTypeFromHandle
.CallerMethodAttribute: The MethodBase of the calling method. This is replaced by the compiler by
ldtoken
of the method reference followed by a call toMethodBase.GetMethodFromHandle
.Example usage:
It was also suggested by @AdamSpeight2008 that a caller-info struct be supported for situations where you want several of these values but don't want to have to declare/annotate multiple parameters.
LDM history:
Beta Was this translation helpful? Give feedback.
All reactions