public class ClassA { public ClassB B {get; privet set;} public ClassA() { B = new CLassB(); } } public class ClassB { public ClassB() { //Here i want to print the class name that call to this consructor (ClassA) } }
System.Diagnostics.StackTrace
System.Diagnostics.StackFrame
StackFrame.GetMethod
System.Reflection.MethodBase
System.Reflection.MethodBase.DeclaringType
StackTrace st = new StackTrace(true); foreach ( StackFrame sf in st.GetFrames()) { Console.WriteLine(sf.GetMethod().DeclaringType); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)