public static string InvokeAnalyseMood(string message, string methodName) { try { Type type = Type.GetType("ExceptionHandling.MoodAnalyzer"); object moodAnalyseObject = MoodAnalyzerFactory.CreateMoodAnalyseUsingParameter("ExceptionHandling.MoodAnalyzer", "MoodAnalyzer", message); MethodInfo analyseMoodInfo = type.GetMethod(methodName); object mood = analyseMoodInfo.Invoke(moodAnalyseObject, null); return(mood.ToString().ToUpper()); } catch (NullReferenceException) { throw new MoodAnalyzerCustomException(MoodAnalyzerCustomException.ExceptionType.NO_SUCH_METHOD, "Method is Not Found"); } }
public static string InvokeAnalyseMood(string className, string constuctor, string message, string methodName) { //Get the instance of the MoodAnalyserClass and create a constructor object moodAnalysis = MoodAnalyzerFactory.CreateMoodAnalyseWithParameter(className, constuctor, message); Type type = typeof(MoodAnalyzer); try { //Fetching the method info using reflection MethodInfo methodInfo = type.GetMethod(methodName); //Invoking the method of Mood Analyser Class Object obj = methodInfo.Invoke(moodAnalysis, null); return(obj.ToString().ToUpper()); } catch (NullReferenceException) { throw new MoodAnalyzerCustomException(MoodAnalyzerCustomException.ExceptionType.NO_SUCH_METHOD, "No such method found"); } }