Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace OopShit
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using Contracts;
- using Entities;
- using Enums;
- public class StartUp
- {
- public static void Main()
- {
- List<Human> humans = new List<Human>();
- var human = new Farmer()
- {
- Name = "gosho"
- };
- string name = "Kenov";
- string education = "it";
- bool condemned = true;
- string work = "softuni";
- Random rng = new Random();
- string habit = rng.Next(10) > 5 ? "drunk" : "literate";
- Enum.TryParse<Habits>(habit, true, out Habits result);
- Human farmer = new Farmer()
- {
- Name = "Nakov",
- Age = 37
- };
- var teacher = new Teacher(name, condemned, work, education, result);
- var child = new Child()
- {
- Name = "Qvor",
- Age = 2
- };
- humans.Add(child);
- humans.Add(teacher);
- humans.Add(farmer);
- string[] skills = new[]
- {
- "Teach",
- "ApplyGrades",
- "Greet",
- "Drink",
- "Sleep",
- "Gathering",
- "KillAnimal"
- };
- foreach (var h in humans)
- {
- Console.WriteLine(h.GetType().Name);
- var abilites = h.GetType().GetRuntimeMethods().Where(x => skills.Any((i => i == x.Name))).ToArray();
- foreach (var a in abilites)
- {
- var hhh = a.Name.Split();
- Type testType = h.GetType();
- object testInstance = Activator.CreateInstance(testType);
- MethodInfo toInvoke = testType.GetMethod(hhh[0]);
- toInvoke.Invoke(testInstance, null);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment