我有以下代碼:確定λ-表達的返回類型
public class ScriptRuntime {
public R Execute<T, R>(Expression<Func<T, R>> expression) {
// ... do something ...
return default(R);
}
}
我這樣稱呼它
var loc = AddIn.Context.ScriptRuntime.Execute<IAgentBaseScript, Vector3?>(x => x.GetInitialLocation(this));
我問我,如果是刪除的的定義可能性返回類型R
,而應該只從表達式中獲取?
例如當我打電話
var loc = AddIn.Context.ScriptRuntime.Execute<IAgentBaseScript>(x => x.GetInitialLocation(this));
並且因爲接口IAgentBaseScript
看起來像
public interface IAgentBaseScript {
Place GetInitialPlace(AgentBase agent);
Vector3? GetInitialLocation(AgentBase agent);
}
它理論上應該是明確的,即返回類型是Vector3
因爲它始終是相同的表達。