Questions tagged [callermembername]

`CallerMemberName` provides useful information about the caller within the called method.

Caller information attributes like CallerMemberName (from the System.Runtime.CompilerServices namespace) provide information about the caller within the called method, e.g.:

public void Log(string message, [CallerMemberName] string memberName = "")
{
    Trace.WriteLine("Log has been called by {0}", memberName);
}

Other caller information attributes are CallerFilePath and CallerLineNumber. More information about that topic can be found at http://msdn.microsoft.com/en-us/library/hh534540.aspx

27 questions
2
votes
2 answers

Override the default behaviour of GetEnumerator

I have a requirement where I need to know the calling method to the GetEnumerator(). The best way I could think would be possibly overriding the default behaviour to GetEnumerator to one that I create i.e GetEnumerator([CallerMemberName]string…
jclarkson
  • 169
  • 3
  • 11
1
vote
1 answer

Allow calling function to get caller's attribute in Python

I want to create a function that will be called whenever the caller gets arguments of wrong instance, that will print caller's __doc__ attribute and exit. The function is the following: def checktype(objects,instances): if not…
Vasilis Lemonidis
  • 636
  • 1
  • 7
  • 25
1
vote
1 answer

Implementing an attribute with similar behavior to CompilerServices.CallerMemberAttribute

It is possible to create an attribute that has a behavior similar to CallerMemberNameAttribute? I mean, I have googled and found this article, that says CallerMemberName is a attribute that belongs to CompilerServices group, or in other words, this…
Jonny Piazzi
  • 3,684
  • 4
  • 34
  • 81
1
vote
3 answers

MVVM CallerMemberName and "magic strings"

New C# 5.0 release introduced something to get rid of "magic strings" in INotifyPropertyChanged implementation like: OnPropertyChanged("CustomerName"); Now it is possible to write just: OnPropertyChanged(); It is possible due to CallerMemberName…
0
votes
1 answer

Using [CallerMemberName] Attribute with Func delegate

I have common class which is used by both GUI and CommandLine applications This class is passed a ReportError function reference which acts differently on GUI and CommandLine. in the GUI: public int GUIReportError(String ToLog) { …
Julien
  • 1
  • 1
0
votes
1 answer

PropertyChanged | CallerMemberName | AmbiguousMatchExcpetion

I get the following error on runtime: AmbiguousMatchExcpetion "Ambiguous Match found." Does someone knows what is the reason for? Class public class MyTrimmedClass : Control, INotifyPropertyChanged { public HtUserGroupSetup…
Dominic Jonas
  • 4,717
  • 1
  • 34
  • 77
0
votes
1 answer

My property does not update using [CallerMemberName]

Admittedly I am new to wpf. But i have spent some time Googling about it all and I am stumped. in essence i want to update my TextBlock in my UI using Binding whenever my Model values change. So this is my Model: using System.ComponentModel; using…
Andrew Simpson
  • 6,883
  • 11
  • 79
  • 179
0
votes
0 answers

CallerMemberName doesn't return propertyName

I'm working with some code that's suddenly stopped functioning. I tracked the problem down to CallerMemberName feature in .NET 4 It seems that it just stopped working, [CallerMemberName] String propertyName = "" returns "", even though it's being…
Joe
  • 6,773
  • 2
  • 47
  • 81
0
votes
2 answers

Is it possible, to evaluate the event of calling a set property?

Let's say, we have an ordinary C# class with one auto get/set property. public class Entity { public String SomeProperty {get;set;} } Is there any event, that is raised and that I can evaluate, when the set method of the SomeProperty is…
Michael
  • 938
  • 1
  • 10
  • 34
0
votes
1 answer

Getting the caller method name - Reflection and CallerInfo attribute

Just bench-marked the performance of using StackTrace and CallerInfo Attributes. Shockingly I found that using StackTrace is much faster though every where I read that To get the caller method name, the preferred approach is CallerInfo…
0
votes
1 answer

Why are Caller Information attributes implemented the way they are?

Disadvantages of the current implementation: They violate the DRY principle as you have to rewrite the parameters everywhere you need them They ruin implementation-hiding as you have to specify those parameters already in the interface - even if…
D.R.
  • 20,268
  • 21
  • 102
  • 205
-1
votes
2 answers

Getting the class name

How to get the class-name with caller info attributes. I strongly say a no to log the class name using reflection. Was able to get the method name using the [CallerMemberName] like below: private void Log(string logMessage,…
1
2