示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter message: ");
            string       message   = Console.ReadLine();
            MoodAnalyser checkmood = new MoodAnalyser(message);
            string       result    = checkmood.AnalyseMood();

            Console.WriteLine(result + " MOOD");
            MoodAnalyserRefection.InvokeAnalyseMood("MyMoodAnalyser.MoodAnalyser", "MoodAnalyser");
        }
 public static string InvokeAnalyseMood(string message, string methodName)
 {
     try
     {
         Type       type            = Type.GetType("MyMoodAnalyser.MoodAnalyser");
         object     moodAnalyserObj = MoodAnalyserRefection.CreateMoodAnalyseUsingParameterizedConstructor("MyMoodAnalyser.MoodAnalyser", "MoodAnalyser", message);
         MethodInfo methodInfo      = type.GetMethod(methodName);
         object     mood            = methodInfo.Invoke(moodAnalyserObj, null);
         return(mood.ToString());
     }
     catch (NullReferenceException)
     {
         throw new MoodAnalysisCustomException(MoodAnalysisCustomException.ExceptionType.NO_SUCH_METHOD, "no such method.");
     }
 }