Exemple #1
0
        private string ComputeNameFromStackTrace()
        {
            StackTrace stackTrace = new StackTrace(false);
            MethodBase method     = null;
            Assembly   assembly   = null;
            int        i;

            // Find the calling assembly
            for (i = 1; i < stackTrace.FrameCount; i++)
            {
                method   = stackTrace.GetFrame(i).GetMethod();
                assembly = method.DeclaringType.Assembly;
                if (assembly != typeof(NamedIndependent).Assembly)
                {
                    break;
                }
            }

            // Find a method in the calling assembly that looks like a property
            // getter; if nothing is found, use the name of the first method
            // in the calling assembly.
            MethodBase candidate = method;
            string     methodName = method.Name, candidateName = methodName;

            do
            {
                if (candidateName.StartsWith("get_"))
                {
                    methodName = candidateName.Substring(4);
                    method     = candidate;
                    break;
                }
                candidate = stackTrace.GetFrame(i).GetMethod();
                if (candidate.DeclaringType.Assembly != assembly)
                {
                    break;                     // quit searching
                }
                candidateName = candidate.Name;
            } while(++i < stackTrace.FrameCount);

            return(string.Intern(MemoizedTypeName.GenericName(method.DeclaringType) + "." + methodName));
        }
Exemple #2
0
 public static string GetClassAndMethodName(Delegate d)
 {
     return(MemoizedTypeName.GenericName(d.Method.DeclaringType) + "." + d.Method.Name);
 }