2017-04-27 7 views
0

の戻り値の決定:私はの定義を削除する可能性があるならば、私は、私を求めています私は、次のコード持っているラムダ式

var loc = AddIn.Context.ScriptRuntime.Execute<IAgentBaseScript, Vector3?>(x => x.GetInitialLocation(this)); 

のようにそれを呼び出す

public class ScriptRuntime { 
    public R Execute<T, R>(Expression<Func<T, R>> expression) { 
     // ... do something ... 
     return default(R); 
    } 
} 

をreturntype 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であることを、明確にする必要がありますたとえば、 。更新なし

答えて

0

にする方法を更新することができますすることはできません結果の型がx => x.GetInitialLocation(this)であると推測すると、コンパイラはまず入力型を推測する必要があります。あなたが気づいたように、それはできません。エラーメッセージはExecuteメソッドの型引数を指定することを示しますが、xの型をコンパイラに知らせるだけで十分です:

scriptRuntime.Execute((IAgentBaseScript x) => x.GetInitialLocation(this)); 
0

は、ExecuteメソッドをC#はR.

もないとは判断できないので、あなたは、あなたが

public Vector3? Execute<T>(Expression<Func<T, Vector3>> expression) 

それとも

public R Execute<T, R>(Expression<Func<T, R>> expression) where R : Vector3? 
関連する問題