Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Mood Analyser App!");
            Console.WriteLine("Enter message");
            MoodAnalyser m = new MoodAnalyser();

            m.message = Console.ReadLine();
            Console.WriteLine("Mood : " + m.AnalyseMood());
            Console.ReadKey();
        }
 public static string SetField(string message, string fieldName)
 {
     try
     {
         MoodAnalyser mood  = new MoodAnalyser();
         Type         type  = typeof(MoodAnalyser);
         FieldInfo    field = type.GetField(fieldName, BindingFlags.Public | BindingFlags.Instance);
         if (message == null)
         {
             throw new MoodAnalyserCustomException(MoodAnalyserCustomException.ExceptionType.NO_SUCH_FIELD, "Message cannot be null");
         }
         field.SetValue(mood, message);
         return(mood.message);
     }
     catch (NullReferenceException)
     {
         throw new MoodAnalyserCustomException(MoodAnalyserCustomException.ExceptionType.NO_SUCH_FIELD, "Field not found");
     }
 }