Is it possible to get actual type from stack trace?

No, since the method is actually declared on Base As long as the method is not overridden, you always get the same MethodInfo instance for the method independent of whether you query it on the base class or on the derived class.

No, since the method is actually declared on Base. As long as the method is not overridden, you always get the same MethodInfo instance for the method independent of whether you query it on the base class or on the derived class. But why do you need the other type in the first place?

There may be another solution to your problem, that's why I'm asking this.

My base class contains basic operations (like delete, insert, etc). If anything is faulty, I want to raise an exception, with finding out the operation type (insert,delete,etc), layer (business logic, data access ,etc), and module of the location of the error. However if the problem is in class A, which is in module "Project1", and base is in "Framework", I want the module to be "Project1", but since the exception was raised in Base, I'll get "Framework"... – TDaver Jan 31 at 12:35 If the members defined in the "Framework" are virtual or abstract and then overridden by the "Project1" classes, you'll get the information you want... – Lucero Jan 31 at 12:40 I've decided that on non-overriden cases, I'll provide the exceptionFactory with the required data (Module and actual ClassName) myself.

If none provided, it will search the StackTrace. – TDaver Jan 31 at 12:48.

Yeah just use this.GetType(). That will return the subclass. So this: public void Foo() { System.Diagnostics.Debug.

Print(this.GetType().ToString()); } should print "A.

2 From my understanding, the ExceptionFactory is a separate class which relies on the stack trace to generate the exception; so it is likely that there is no "this" available. – Lucero Jan 31 at 12:30 Exactly, although if there are no other solutions it will take a Type parameter (however that wouldn't be very nice, because it will only correspond with the first level of the trace, so it's not a global solution...) – TDaver Jan 31 at 12:32 This will work as long as you are inside the method or at least within the same type. When you make a call to a method within another type, this will (obviously) no longer be an option, regardless of whether the invoked helper method is static or not.

– Fredrik Mörk Jan 31 at 12:36 @TDaver could you not pass in "this" to the ExceptionFactory constructor? – Jack Allan Jan 31 at 13:03 ExceptionFactory is static, there was no reason to create a new instance just for one "throw"... – TDaver Jan 31 at 13:29.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions