private static object InvokeMethod(Type type, MethodInfo method, object[] arguments) { try { var instance = method.IsStatic ? null : Activator.CreateInstance(type); var invokeResult = method.Invoke(instance, arguments); if (invokeResult == null) { return(null); } if (method.ReturnType.IsGenericType) { if (method.ReturnType.GetGenericTypeDefinition() == typeof(ValueTask <>) || method.ReturnType.GetGenericTypeDefinition() == typeof(Task <>)) { return((invokeResult as dynamic).Result); } } if (method.ReturnType == typeof(Task) || method.ReturnType == typeof(ValueTask)) { (invokeResult as dynamic).GetAwaiter().GetResult(); return(null); } return(invokeResult); } catch (Exception ex) { throw CodeException.InvokeMethodError(ex); } }
private static object DeserializeParameter(JsonElement jsonElement, ParameterInfo parameterInfo) { try { return(JsonUtils.Deserialize(jsonElement.GetRawText(), parameterInfo.ParameterType)); } catch (Exception ex) { throw CodeException.ConvertParameterValueError(parameterInfo, ex); } }
private static JsonDocument ReadInputFile(string filePath) { try { return(JsonUtils.FromFile(filePath)); } catch (Exception ex) { throw CodeException.ReadInputFileError(filePath, ex); } }