private static IQueryable <object> ProjetarDeFormaDinamicaSelecionada <T>(
            this IQueryable <T> consulta,
            string[] campos,
            out MapperConfiguration configuracoesDeMapeamento)
        {
            var descricoes = new DnDescricaoDaClasse(typeof(T), campos);
            var id         = UtilitarioDeRandomico.ObterString(6);
            var nomeDaDll  = $"DnDll_{id}";
            var tipo       = descricoes.CriarOTipo(nomeDaDll);
            var tipos      = new List <Tuple <Type, Type> >();

            descricoes.ObterTodosOsTiposPorDescricao(tipos);

            configuracoesDeMapeamento = new MapperConfiguration(
                cfg =>
            {
                cfg.CreateMap(typeof(T), typeof(T));
                cfg.CreateMap(typeof(T), tipo).ReverseMap();
                tipos.ForEach(x => cfg.CreateMap(x.Item1, x.Item2).ReverseMap());
            });

            var metodo = typeof(Extensions).GetMethods()
                         .Where(x => x.Name == nameof(Extensions.ProjectTo))
                         .ToList()[2].MakeGenericMethod(tipo);//Todo - Isso deve ser revisto, há uma chance de problemas futuros aqui

            var ret = metodo.Invoke(
                null,
                new object[]
            {
                consulta, configuracoesDeMapeamento, null, campos.Select(x => x).ToArray()
            });

            return(ret as IQueryable <object>);
        }
Esempio n. 2
0
        public static object GetPrimitiveExampleValue(this Type type)
        {
            type = type.GetNonNullableType();

            if (type.EhNumerico())
            {
                return(UtilitarioDeRandomico.NextRandom(99));
            }
            if (type == typeof(DateTime))
            {
                return(DateTime.Now);
            }
            if (type == typeof(string) && type == typeof(String))
            {
                return(UtilitarioDeRandomico.ObterString(6));
            }

            return(type.GetDnDefaultValue());
        }
Esempio n. 3
0
        private async Task GenerateNewEntityCodes(object compositionValue, PropertyInfo property, int max = 0)
        {
            List <object> notExists;

            do
            {
                var list = new object[10];
                for (int i = 0; i < list.Length; i++)
                {
                    list[i] = UtilitarioDeRandomico.GetRandomValue(property, max);
                }

                notExists = await ExistOnListAsync(property, compositionValue.GetType(), list); // Verificar se esse cast vai funcionar
            }while (notExists.Count == 0);

            var value = notExists.Next();

            SessionRequest.SetCodeAvailableForEntity(compositionValue.GetType().FullName + property.Name, notExists);
            property.SetValue(compositionValue, value);
        }
        public static object GetExampleValue(this PropertyInfo property, int max_ = 0)
        {
            if (property.PropertyType.GetNonNullableType().EhNumerico())
            {
                var min = property.GetCustomAttribute <DnPropriedadeJsonAtributo>()?.Minimo ?? property.GetCustomAttribute <RangeAttribute>()?.Minimum;
                var max = property.GetCustomAttribute <DnPropriedadeJsonAtributo>()?.Maximo ?? property.GetCustomAttribute <RangeAttribute>()?.Maximum;
                if (min == null || max == null)
                {
                    return(UtilitarioDeRandomico.NextRandom(int.MaxValue));
                }

                if (max.ToString() == "0" && property.PropertyType.EhNumerico())
                {
                    max = property.PropertyType.GetMaxValueOfNumber().DnCast <double>();
                }

                return(UtilitarioDeRandomico.NextRandom((int)min, (double)max));
            }

            if (property.PropertyType.GetNonNullableType() == typeof(string) && property.PropertyType.GetNonNullableType() == typeof(String))
            {
                var min = property.GetCustomAttribute <DnPropriedadeJsonAtributo>()?.Minimo ?? property.GetCustomAttribute <MinLengthAttribute>()?.Length;
                var max = max_ == 0 ? (property.GetCustomAttribute <DnPropriedadeJsonAtributo>()?.Maximo ?? property.GetCustomAttribute <MaxLengthAttribute>()?.Length) : max_;
                max ??= 64;
                min ??= 0;
                if (min == null)
                {
                    return(UtilitarioDeRandomico.ObterString(max.Value));
                }
                if (max == null)
                {
                    return(UtilitarioDeRandomico.ObterString(min.Value));
                }

                return(UtilitarioDeRandomico.ObterString(max.Value));
            }

            return(property.PropertyType.GetDnDefaultValue());
        }