resに戻り値を返したいのですが、書き方がわかりません。
using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace PrivateAccess { class Program { static void Main(string[] args) { } } public class PrivateAccess { /// <summary> public PrivateAccess() { } private async Task btn_Click2(object sender, EventArgs e) { try { await LedSwitchTask("1 0"); } catch { throw; } } private async Task<string> LedSwitchTask(string allArg) { var res = await Task.Run(new Func<string>(() => { string chan; chan = allArg.Substring(0, 1); Thread.Sleep(800); return "OK"; })); return res; //throw new NotImplementedException(); } } } using Microsoft.VisualStudio.TestTools.UnitTesting; using PrivateAccess; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Reflection; namespace PrivateAccess.Tests { [TestClass()] public class PrivateAccessTests { [TestMethod()] //[DeploymentItem("SampleLibrary.dll")] public async Task privateasynctest() { try { PrivateAccess theObject = new PrivateAccess(); Type t = theObject.GetType(); MethodInfo dynMethod = t.GetMethod("btn_Click2", BindingFlags.NonPublic | BindingFlags.Instance); // res に 戻り値を返したい // var res = await (Task) dynMethod.Invoke(theObject, new string[] { null, null }); await (Task)dynMethod.Invoke(theObject, new string[] { null, null }); } catch (Exception ex) { string s; s = ex.Message; } } } }コード
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/21 01:45