Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Mood Analyzer Program");
            Console.WriteLine("Enter message: ");
            string       message   = Console.ReadLine();
            MoodAnalyzer checkmood = new MoodAnalyzer(message);
            string       result    = checkmood.AnalyseMood(message);

            Console.WriteLine(result + " MOOD");
            MoodAnalyzerFactory.CreateMoodAnalyserObject("MoodAnalyzerProgram.MoodAnalyzer", "MoodAnalyzer");
        }
 public static string SetField(string message, string fieldName)
 {
     try
     {
         MoodAnalyzer moodAnalyser = new MoodAnalyzer();
         Type         type         = typeof(MoodAnalyzer);
         FieldInfo    field        = type.GetField(fieldName, BindingFlags.Public | BindingFlags.Instance);
         if (message == null)
         {
             throw new CustomException(CustomException.ExceptionType.EMPTY_MESSAGE, "message should not be null.");
         }
         field.SetValue(moodAnalyser, message);
         return(moodAnalyser.message);
     }
     catch (NullReferenceException)
     {
         throw new CustomException(CustomException.ExceptionType.NO_SUCH_FIELD, "no such field found.");
     }
 }