Пример #1
0
        static void Main()
        {
            var assembly = Assembly.Load(new AssemblyName("CoolLibrary"));

            var type = assembly.GetType("CoolLibrary.SomeCoolClass");

            dynamic someCoolClass = new ExposedObject(type);

            string result = someCoolClass.CoolMethod(42, "Something cool");

            Console.WriteLine(result);

            someCoolClass.Name = "My Tested ASP.NET";

            Console.WriteLine(someCoolClass.Name);
        }
Пример #2
0
        static void Main(string[] args)
        {
            var assembly = Assembly.Load(new AssemblyName("CoolLibrary"));

            var type = assembly.GetTypes().FirstOrDefault(t => t.Name == "CoolClass");

            //var methodInfo = type.GetMethod("CoolMethod");
            //methodInfo.Invoke(null, new object[0]);


            dynamic someCoolClass = new ExposedObject(type);

            someCoolClass.CoolMethod();

            someCoolClass.Name = "Test";

            Console.WriteLine(someCoolClass.Name);
        }
Пример #3
0
        static void Main(string[] args)
        {
            Assembly   assembly = Assembly.Load(new AssemblyName("CoolLibrary"));
            Type       type     = assembly.GetType("CoolLibrary.CoolClass");
            MethodInfo method   = type.GetMethod("CoolMethod", BindingFlags.NonPublic | BindingFlags.Static);
            string     result   = (string)method.Invoke(null, new object[] { 18, "Atanas Vasilev" });

            Console.WriteLine(result);

            Console.WriteLine();
            Console.WriteLine("Invocation using dynamic");

            dynamic coolClass = new ExposedObject(type);

            //Call methods
            string dynamicResult = coolClass.CoolMethod(18, "Atanas Vasilev");
            int    integerSum    = coolClass.Sum(12, 15);
            double collectionSum = coolClass.SumCollection(new List <double>()
            {
                12.5, 12.3
            });

            coolClass.PrintHelloWord();

            //Set and get properties
            coolClass.Name  = "Dynamic reflection";
            coolClass.Value = 10.5;
            string name  = coolClass.Name;
            double value = coolClass.Value;

            Console.WriteLine(name);
            Console.WriteLine(value);
            Console.WriteLine(dynamicResult);
            Console.WriteLine("Integer sum " + integerSum);
            Console.WriteLine("Collection sum " + collectionSum);
        }