// UC6:- Use Reflection to invoke Method –analyseMood 
        public string InvokeAnalyzerMethod(string message, string methodName)
        {
            try
            {
                Type type = typeof(MoodAnalyzer);

                MethodInfo analyzerMoodInfo = type.GetMethod(methodName);
                MoodAnalyzerFactory Factory = new MoodAnalyzerFactory();
                object moodAnalyzerObject = Factory.CreateMoodAnalyzerParameterObject("MoodAnalyzerProblem.MoodAnalyzer", "MoodAnalyzer", message);
                object mood = analyzerMoodInfo.Invoke(moodAnalyzerObject, null);
                return mood.ToString();
            }
            catch (NullReferenceException)
            {
                throw new MoodAnalyzerException(MoodAnalyzerException.ExceptionType.NO_SUCH_METHOD, "Method is not found");
            }
        }
Esempio n. 2
0
 static void Main(string[] args)
 {
     Console.WriteLine("Welcome to Mood Analyser:");
     MoodAnalyzer        mood    = new MoodAnalyzer();
     MoodAnalyzerFactory factory = new MoodAnalyzerFactory();
 }