public static object CallSelectOrNoSelectMethod(this IDnEspecificacaoBase spec, string methodName, params object[] parameters) { var paramList = new List <object> { spec }; paramList.AddRange(parameters); parameters = paramList.ToArray(); if (spec != null && spec.Servico == null) { throw new DesenvolvimentoIncorretoException($"The past spec does not have a valid service. See at the time the spec is created if a service has been passed in the spec creator."); } if (spec is IDnEspecificacaoAlternativa spec2) { var service = spec2.TipoDeEntidade.GetServiceInstanceByEntity(spec2.Servico.SessaoDaRequisicao); var method = service.GetType().GetMethod($"{methodName}Select"); if (method == null) { throw new DesenvolvimentoIncorretoException($"Method not found: {methodName}Select"); } return(method.MakeGenericMethod(spec2.TipoDeRetorno).Invoke(service, parameters)); } if (spec is IDnEspecificacao spec3) { var service = spec3.TipoDeEntidade.GetServiceInstanceByEntity(spec3.Servico.SessaoDaRequisicao); var method = service.GetType().GetMethodWithoutAmbiguity(methodName, parameters); if (method == null) { throw new DesenvolvimentoIncorretoException($"Method not found: {methodName}"); } return(method.Invoke(service, parameters)); } throw new DesenvolvimentoIncorretoException("The specification is of a different type than expected"); }
public virtual async Task <bool> ExisteAlternativoAsync <TO>(IDnEspecificacaoBase spec) { return(await GetSpecSelect <TO>(spec).ConverterParaIQueryable(Query).AnyAsync()); }
public virtual async Task <bool> ExisteAsync(IDnEspecificacaoBase spec) { return(await GetSpec(spec).ConverterParaIQueryable(Query).AnyAsync()); }
public static bool Exists(this IDnEspecificacaoBase spec) { return((bool)spec.Execute(nameof(Exists))); }
public static object Execute(this IDnEspecificacaoBase spec, string method, params object[] parameters) { return(spec.CallSelectOrNoSelectMethod(method, parameters)); }
public static object FirstOrDefault(this IDnEspecificacaoBase spec) { return(spec.Execute(nameof(FirstOrDefault))); }
public static object List(this IDnEspecificacaoBase spec, DnPaginacao pagination = null) { return(spec.Execute(nameof(List), new object[] { pagination })); }