private static Exception LogAndRethrowStubInvocationError(Exception error, Type dynamicInvokerType, string invokedApiName, Type invokerTargetType)
 {
     return(ErrorUtil.LogAndRethrowStubInvocationError(ErrorUtil.ErrorInvokingStubbedApiMsg,
                                                       error,
                                                       dynamicInvokerType,
                                                       invokedApiName,
                                                       isStaticApi: true,
                                                       invokerTargetType,
                                                       null));
 }
 private Exception LogAndRethrowStubInvocationError(Exception error, string invokedApiName, bool isStaticApi, Type invokerTargetType)
 {
     return(ErrorUtil.LogAndRethrowStubInvocationError(ErrorUtil.ErrorInvokingStubbedApiMsg,
                                                       error,
                                                       typeof(DynamicInvoker_DiagnosticListener),
                                                       invokedApiName,
                                                       isStaticApi,
                                                       invokerTargetType,
                                                       _diagnosticListenerInstance));
 }
        public static DiagnosticListenerStub Wrap(object diagnosticListenerInstance)
        {
            if (diagnosticListenerInstance == null)
            {
                return(NoOpSingeltons.DiagnosticListenerStub);
            }

            DynamicInvoker_DiagnosticListener invoker = null;

            try
            {
                invoker = DynamicInvoker.Current.DiagnosticListener;
                DynamicInvokerHandle <DynamicInvoker_DiagnosticListener> handle = invoker.GetInvokerHandleForInstance(diagnosticListenerInstance);
                return(new DiagnosticListenerStub(diagnosticListenerInstance, handle));
            }
            catch (Exception ex)
            {
                throw ErrorUtil.LogAndRethrowStubInvocationError(ErrorUtil.CannotCreateStubMsg,
                                                                 ex,
                                                                 typeof(DynamicInvoker_DiagnosticListener),
                                                                 invoker?.TargetType,
                                                                 diagnosticListenerInstance);
            }
        }