private static bool IsBuiltInErrorResponse <T>(IScimResponse <T> originalResponse)
        {
            var typeInfo = originalResponse.GetType().GetTypeInfo();

            return((originalResponse is ScimErrorResponse <T>) ||
                   (typeInfo.IsGenericType && typeof(ScimErrorResponse <>).GetTypeInfo().IsAssignableFrom(typeInfo.GetGenericTypeDefinition().GetTypeInfo())));
        }
        internal static IScimResponse <T2> CreateGenericErrorResponse <T, T2>(IScimResponse <T> originalResponse, ScimError error)
        {
            if (IsBuiltInErrorResponse(originalResponse))
            {
                return(new ScimErrorResponse <T2>(error));
            }

            try
            {
                return(Activator.CreateInstance(
                           originalResponse.GetType()
                           .GetGenericTypeDefinition()
                           .MakeGenericType(typeof(T2)),
                           error) as IScimResponse <T2>);
            }
            catch (TargetInvocationException)
            {
                // No supportable constructor found! Return default.
                return(new ScimErrorResponse <T2>(error));
            }
        }