Example #1
0
    public static void Main(string[] args)
    {
        test_class  a = new test_class();
        test_struct b = new test_struct();

        a.i = 1;
        a.something();

        b.i = 1;
        b.something();
    }
Example #2
0
        static void invoke_method()
        {
            Type t = typeof(test_class);

            Console.WriteLine("\nВызов метода через рефлексию:");
            //Создание объекта через рефлексию
            test_class test = (test_class)t.InvokeMember(null, BindingFlags.CreateInstance, null, null, new object[] { });

            object[] parameter = new object[] {  };
            //Вызов метода
            object result = t.InvokeMember("sum", BindingFlags.InvokeMethod, null, test, null);
        }
Example #3
0
 public void concat_string_with_class()
 {
     var t = new test_class();
     var a = "hello " + t;
 }
Example #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Часть 1");
            // метод с делегатом
            Print(5, -10, true, "Умножение", multiply);
            // метод с делегатом на лямда-функции
            Print(-10, 5, false, "Сумма",
                  (str, a, b, abs) =>
            {
                Console.Write(str);
                if (abs)
                {
                    Console.WriteLine(Math.Abs(a + b));
                }
                else
                {
                    Console.WriteLine(a + b);
                }
            }
                  );
            // создание 2 делегатов на лямда-выражениях, те же сумма и умножение
            Action <string, int, int, bool> act1 = (str, a, b, abs) =>
            {
                Console.Write(str);
                if (abs)
                {
                    Console.WriteLine(Math.Abs(a + b));
                }
                else
                {
                    Console.WriteLine(a + b);
                }
            };
            Action <string, int, int, bool> act2 = (str, a, b, abs) =>
            {
                Console.Write(str);
                if (abs)
                {
                    Console.WriteLine(Math.Abs(a * b));
                }
                else
                {
                    Console.WriteLine(a * b);
                }
            };
            // обобщённый делегат
            Action <string, int, int, bool> chain = act1 + act2;

            // вызов через action
            Print2(-5, 10, true, "сумма или умножение по модулю: ", chain);


            Console.WriteLine("Часть 2");
            Console.WriteLine("");

            test_class obj = new test_class();
            Type       t   = obj.GetType();

            Console.WriteLine("Тип: " + t.FullName);
            Console.WriteLine("Пространство имён: " + t.Namespace);
            Console.WriteLine("Информация о сборке: " + t.AssemblyQualifiedName);
            Console.WriteLine("Конструкторы: ");
            foreach (var x in t.GetConstructors())
            {
                Console.WriteLine(x);
            }
            Console.WriteLine("Методы: ");
            foreach (var x in t.GetMethods())
            {
                Console.WriteLine(x);
            }
            Console.WriteLine("Свойства: ");
            foreach (var x in t.GetProperties())
            {
                Console.WriteLine(x);
            }
            Console.WriteLine("Поля данных: ");
            foreach (var x in t.GetFields())
            {
                Console.WriteLine(x);
            }

            attributes_in_class();
            invoke_method();
            Console.ReadKey();
        }