/// <summary>
 /// UC 6 : Invokes the AnalyseMood method and returns message indicating mood type.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="methodName">Name of the method.</param>
 /// <returns></returns>
 /// <exception cref="MoodAnalyserCustomException">Exception: method not found</exception>
 public static string InvokeAnalyseMood(string message, string methodName)
 {
     try
     {
         Type       type = Type.GetType("MoodAnalyzerProblem.MoodAnalyser");
         object     moodAnalyserObject = MoodAnalyserReflector.CreateMoodAnalyserObject("MoodAnalyzerProblem.MoodAnalyser", "MoodAnalyser", message);
         MethodInfo methodInfo         = type.GetMethod(methodName);
         object     mood = methodInfo.Invoke(moodAnalyserObject, null);
         return(mood.ToString());
     }
     catch (NullReferenceException)
     {
         throw new MoodAnalyserCustomException(MoodAnalyserCustomException.ExceptionType.NO_SUCH_METHOD, "Exception: method not found");
     }
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to mood analyzer portal!");
            Console.WriteLine("Type how you feeling right now: ");
            string       mood         = Console.ReadLine();
            MoodAnalyser moodAnalyser = new MoodAnalyser(mood);

            moodAnalyser.AnalyseMood();
            try
            {
                Console.WriteLine("UC 4-7:");
                MoodAnalyserReflector.CreateMoodAnalyserObject("MoodAnalyzerProblem.MoodAnalyser", "MoodAnalyser");
                MoodAnalyserReflector.CreateMoodAnalyserObject("MoodAnalyzerProblem.MoodAnalyser", "MoodAnalyser", "happy");
                MoodAnalyserReflector.InvokeAnalyseMood("Happy", "AnalyseMood");
                Console.WriteLine(MoodAnalyserReflector.SetField("HAPPY", "message"));
            }
            catch (MoodAnalyserCustomException exception)
            {
                Console.WriteLine(exception.Message);
            }
        }