How to get the name of the variable calling the current method in C# pre version 6 We need to implement custom software analytics to trace the usage of the application. We have a common Command base class so the idea if to trace there something that allows us to know which command has been executed.  Consider the following sample code on a WPF Window with 1 Button:  public partial class MainWindow : Window {     private readonly Command _commandName = new Command();      public MainWindow()     {         InitializeComponent();     }      private void Button_Click(object sender, RoutedEventArgs e)     {         _commandName.Execute();     } }  public class Command {     public void Execute()     {         MessageBox.Show(this.GetCommandName());         // ....     }      private string GetCommandName()     {         string commandName = null;          MethodBase method = new StackTrace(new StackFrame(2)).GetFrame(0).GetMethod();         Type callingType = method.DeclaringType;          if (callingType != null)         {             IList&lt;FieldInfo&gt; variables = callingType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetField | BindingFlags.Instance).Where(f =&gt; f.FieldType == typeof(Command)).ToList();              if (variables.Count == 1)             {                 commandName = variables[0].Name;             }         }          return commandName;     } }   This code will show the variable name but only if there is one Command variable on the calling type. Is there a way of getting the calling variable name directly without going thru reflection?  The output of this code is (and should be) _commandName not Button_Click.
How can I find the method that called the current method? When logging in C#, how can I learn the name of the method that called the current method? I know all about System.Reflection.MethodBase.GetCurrentMethod(), but I want to go one step beneath this in the stack trace. I've considered parsing the stack trace, but I am hoping to find a cleaner more explicit way, something like Assembly.GetCallingAssembly() but for methods.
What is the relationship between symmetry and degeneracy in quantum mechanics? var functionName = function() {} vs function functionName() {} I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.  The previous developer used two ways of declaring functions and I can't work out if there is a reason behind it or not.  The two ways are:  var functionOne = function() {     // Some code };     function functionTwo() {     // Some code }   What are the reasons for using these two different methods and what are the pros and cons of each? Is there anything that can be done with one method that can't be done with the other? Where's the energy in a boosted capacitor? Suppose I look at a parallel plate capacitor in its rest frame and calculate the electrostatic energy, $E$.  Next, I look at the same capacitor in a primed frame boosted in the direction perpendicular to the plane of the plates. In this frame, the $E$-field is the same strength, there is no magnetic field, and the volume over which the $E$-field extends is less by a factor $1/\gamma$. This suggests $E' = \frac{1}{\gamma} E$, but relativity states that energy transforms as $E' = \gamma E$.   Where is the missing energy? Parametric Form for a General Parabola It is well known that a parametric form of the parabola $y^2=4ax$ is $(at^2, 2at)$.      What are possible parametric forms of the general parabola   $$(Ax+Cy)^2+Dx+Ey+F=0$$   ? When the loop is the figure shown below will be rotated in clockwise direction the the slip ring connected to the red segment of the loop will give us the positive voltage and the slip ring connected to the black segment of the loop will give us negative voltage according to the Flemings right hand rule.  What if the loop is rotated in counter clockwise direction ? Will the slip rings provide us the same polarities which they were giving when the loop was moving clockwise ?  Plus  The voltage from the loop is given by the equation.  V(t) = Vmaximum * sin (theta)  Where theta is the positive angle the red segment makes in the clockwise direction or in counter clockwise direction from this position ? What is a 'Closure'? I asked a question about Currying and closures were mentioned. What is a closure? How does it relate to currying? I have a scenario where I have multiple threads adding to a queue and multiple threads reading from the same queue. If the queue reaches a specific size all threads that are filling the queue will be blocked on add until an item is removed from the queue.  The solution below is what I am using right now and my question is: How can this be improved?  Is there an object that already enables this behavior in the BCL that I should be using?  internal class BlockingCollection&lt;T&gt; : CollectionBase, IEnumerable {     //todo: might be worth changing this into a proper QUEUE      private AutoResetEvent _FullEvent = new AutoResetEvent(false);      internal T this[int i]     {         get { return (T) List[i]; }     }      private int _MaxSize;     internal int MaxSize     {         get { return _MaxSize; }         set         {             _MaxSize = value;             checkSize();         }     }      internal BlockingCollection(int maxSize)     {         MaxSize = maxSize;     }      internal void Add(T item)     {         Trace.WriteLine(string.Format("BlockingCollection add waiting: {0}", Thread.CurrentThread.ManagedThreadId));          _FullEvent.WaitOne();          List.Add(item);          Trace.WriteLine(string.Format("BlockingCollection item added: {0}", Thread.CurrentThread.ManagedThreadId));          checkSize();     }      internal void Remove(T item)     {         lock (List)         {             List.Remove(item);         }          Trace.WriteLine(string.Format("BlockingCollection item removed: {0}", Thread.CurrentThread.ManagedThreadId));     }      protected override void OnRemoveComplete(int index, object value)     {         checkSize();         base.OnRemoveComplete(index, value);     }      internal new IEnumerator GetEnumerator()     {         return List.GetEnumerator();     }      private void checkSize()     {         if (Count &lt; MaxSize)         {             Trace.WriteLine(string.Format("BlockingCollection FullEvent set: {0}", Thread.CurrentThread.ManagedThreadId));             _FullEvent.Set();         }         else         {             Trace.WriteLine(string.Format("BlockingCollection FullEvent reset: {0}", Thread.CurrentThread.ManagedThreadId));             _FullEvent.Reset();         }     } } PHP syntax for dereferencing function result Pandas Merging 101 Stern-Brocot tree where each node has two fathers Package Listings Warning: Text dropped after begin of listing when calling function I'm trying to this:  \newcommand{\code}[1] {\begin{lstlisting} {#1} \end{lstlisting} }   But I keep getting this error:  Package Listings Warning: Text dropped after begin of listing   I'm calling \usepackage and all so, do any of you knows how to solve this? I'd like to setup a WCF service to send emails. The System.Net.MailMessage doesn't seem to be serializable, and cannot be passed in a [DataContract]  The error I receive is      Type 'System.Net.Mail.MailAddress'   cannot be serialized. Consider marking   it with the DataContractAttribute   Any suggestions? PHP generate file for download then redirect At some point in time (about a week ago) something happened to my Motorola Moto Z2 Play / Android 8.0 that caused my base apps to not have access to my media files (i.e. audio, photos etc.). Examples:  all my custom ringtones (i.e. based on my own media files) were reset to default sound:  Contact apps reset custom ringtones for contacts to default one, Alarms &amp; Clock app reset custom alarm tone to default one, SMS (Messages) app reset custom message notification tone to default one, system-wide default notification tone (set by me to custom) was reset as well, system-wide default ringtone (set by me to custom one) was reset,    because my contacts app keeps saying: &quot;No pictures are available on the device&quot;.  While first situation is resolved. I see my custom ringtone files in the list and I can go through my contacts and assign them again. But second situation is not resolved. I see this error all the time and I cannot change any contact's photo. This is verified as not a bug (tested three different contacts-like applications and all of them shows exactly the same message, when trying to change contact's photo). But still, it seems that problem is limited to contacts-related apps only. Other apps still has read and write access to my custom files. For example: :  (read) I can pick any photo or other custom file and attach it to an e-mail, send it as MMS or share it in any other way or (read) upload it to OneDrive or Google Drive etc. or (write) my Camera app is still able to make new photos and store them in &quot;DCIM&quot; or (write) my sound recorder is able to record sound and write audio files.  The only thing that has changed on my phone recently and that I suspect as the cause of above metioned situation was Android 7.1.2 --&gt; Android 8.0.0 update. Is there anything I can do (since replacing contacts app didn't resolve the situation) or check in this case? Or resetting the phone to factory defaults is the only option that I am left with? EDIT: I have cleared cache and data of media app, as suggested in comment. It didn't help. Proofs of Determinants of Block matrices CAST and IsNumeric Why would the following query return "Error converting data type varchar to bigint"?  Doesn't IsNumeric make the CAST safe?  I've tried every numeric datatype in the cast and get the same "Error converting..." error.  I don't believe the size of the resulting number is a problem because overflow is a different error.  The interesting thing is, in management studio, the results actually show up in the results pane for a split second before the error comes back.  SELECT CAST(myVarcharColumn AS bigint)   FROM myTable   WHERE IsNumeric(myVarcharColumn) = 1 AND myVarcharColumn IS NOT NULL   GROUP BY myVarcharColumn   Any thoughts? Can I set the start point of a bezier curve? (used to show two posts from MSE)   (there used to be a list of the accounts)   (it was there) seems to be fixed How to remove time from date? Recording claimable expenses in GnuCash I am new to accounting and trying to learn a few things as my accounts get more and more complicated.  I currently use GnuCash to record simple income/expenses/assets/liabilities and have had a new situation I don't know how to record.  I am currently billing some expenses for work and for my kayak club to my personal credit card.  Under normal circumstances I would do the following (my +/- may be backwards):  Expense +$100 Credit Card -$100  and then when the credit card bill comes I would pay it off  Credit Card +$100 Chequing Account -$100  For expenses that I get reimbursements for I would like to be able to note that I paid for the expense with my credit card and that I paid off my credit card with my chequing account.  At the same time, I would like to be able to create another parent account (maybe "claimable expenses") that shows that I purchased the item, and was then reimbursed so that an individual expense for work or my club has a zero balance.  I tried to look this up in previous threads but didn't quite understand how to apply this to my situation Any advice would be appreciated.