/// <summary> /// Retorna o delegate para uso. /// </summary> /// <typeparam name="T">Delegate</typeparam> /// <returns></returns> /// <exception cref="ACBrException"></exception> protected virtual T GetMethod <T>() where T : class { if (!methodList.ContainsKey(typeof(T))) { throw CreateException($"Função não adicionada para o [{nameof(T)}]."); } var method = methodList[typeof(T)]; if (methodCache.ContainsKey(method)) { return(methodCache[method] as T); } var mHandler = LibLoader.GetProcAddress(handle, method); if (mHandler == IntPtr.Zero || mHandler == MinusOne) { throw new ArgumentNullException("Função não encontrada: " + method); } var methodHandler = LibLoader.LoadFunction <T>(mHandler); methodCache.Add(method, methodHandler as Delegate); return(methodHandler); }
/// <summary> /// Retorna o delegate para uso. /// </summary> /// <typeparam name="T">Delegate</typeparam> /// <returns></returns> /// <exception cref="ACBrException"></exception> protected virtual T GetMethod <[DelegateConstraint] T>() where T : class { if (!methodList.ContainsKey(typeof(T))) { throw CreateException($"Função não adicionada para o [{nameof(T)}]."); } var method = methodList[typeof(T)]; this.Log().Debug($"{className} : Acessando o método [{method}] da biblioteca."); if (methodCache.ContainsKey(method)) { return(methodCache[method] as T); } var mHandler = LibLoader.GetProcAddress(handle, method); Guard.Against <ArgumentNullException>(mHandler == IntPtr.Zero || mHandler == MinusOne, "Função não encontrada: " + method); var methodHandler = LibLoader.LoadFunction <T>(mHandler); this.Log().Debug($"{className} : Método [{method}] carregado."); methodCache.Add(method, methodHandler as Delegate); return(methodHandler); }