Esempio n. 1
0
    public static void Main()
    {
        var teste = new Teste();

        teste.ListProperties();
        WriteLine(teste.GetPropValue <int>("y"));
        var teste2 = new Teste2();

        teste2.ListFields();
    }
        public void ExecutarMetodo <T>(
            ref T tipo,
            Expression <Func <T, object> > propriedade,
            Teste2 metodo,
            object parametros)
        {
            bool executaConsulta = tipo == null;

            try
            {
                if (tipo != null)
                {
                    MemberExpression memberExpression = null;
                    UnaryExpression  unaryExpression  = propriedade.Body as UnaryExpression;

                    if (unaryExpression == null)
                    {
                        memberExpression = propriedade.Body as MemberExpression;
                    }
                    else
                    {
                        memberExpression = unaryExpression.Operand as MemberExpression;
                    }

                    object valorPropriedade = tipo.GetType().GetProperty(memberExpression.Member.Name).GetValue(tipo, null);


                    executaConsulta = "a".ToString().CompareTo(valorPropriedade.ToString()) != 0;
                }
            }
            catch
            {
                throw new Exception("# ERRO # Sintaxe incorreta para a propriedade.");
            }

            if (executaConsulta)
            {
                var retorno = (metodo as Teste2).Invoke(parametros);

                if (retorno is Array)
                {
                    retorno = (retorno as Array)
                              .OfType <T>()
                              .FirstOrDefault();
                }

                tipo = (T)retorno;
            }
        }
        static void Main(string[] args)
        {
            int e;

            Console.WriteLine("Por favor escolha qual questao rodar:\n1- Para Qustao 01\n2- Para questao 02");
            e = int.Parse(Console.ReadLine());
            if (e == 1)
            {
                Teste t = new Teste();
                t.rodar(0, 0, 0);
            }
            if (e == 2)
            {
                Teste2 t2 = new Teste2();
                t2.rodar(0, 0, 0, 0);
            }
            Console.ReadKey();
        }
Esempio n. 4
0
 static void Main(string[] args)
 {
     Teste2 ts = new Teste2();
 }