public static MethodBase GetConstructingMethod()
{
var trace = new StackTrace(false);
var frames = trace.GetFrames();
if (frames == null)
{
throw new Exception("Unable to get the StackFrames from the StackTrace.");
}
if (frames[1].GetMethod().IsConstructor == false)
{
throw new ArgumentException("You may only call GetConstructingMethod from a Constructor.");
}
var frame = frames
.Skip(1)
.First(x => x.GetMethod().IsConstructor == false);
return frame.GetMethod();
}