[英]How to call multiple WCF methods in sequence without blocking the UI thread?
[英]How to call sequence of function?
實際上,我需要知道這條線是如何執行的。
例:
Browser("InternetExplorer").Page("Stackoverflow").WebElement("textbox").set "user"
以上幾行的執行方式類似於將瀏覽器設置為Internet Explorer,並在其中找到頁面“ stackoverflow”,然后在其中找到Webelement“文本框”,然后將其值設置為“用戶”。 這樣就完成了操作。
我想知道此序列調用是如何完成的。 我不希望將瀏覽器設置為Internet Explorer等。
我需要執行一個簡單的語句
Fun(“ add”)。values(“ 2,3”)。compute
我需要通過調用“ add”函數來執行上面的行,然后將值“ 2,3”作為參數傳遞,然后將“ compute”添加進去,最終結果應返回“ 5”。
這個怎么做? 我們是否必須對“ Fun”和“ values”使用不同的類,還是需要將它們實現為同一類的“函數”。
如何處理序列調用?
返回對現有對象的引用就可以實現此效果:
class Operator
{
public:
Operator(const string& opAsStr)
{
...
}
Operator& Values(const string& operands)
{
....
return *this;
}
int Compute() // Compute must be a function, no properties in C++
{
...
}
};
// Usable like this
Operator("Add").Values("2,3").Compute()
通過定義更多返回*this
函數,您可以鏈接許多調用。 請注意,您可以返回一個值(即,用Operator
代替引用,或根據用例使用const引用)。 您還可以返回對另一個類的對象的引用(或值):
class A
{
public:
void DoSomething()
{
....
}
};
class B
{
public:
A MakeA()
{
return A();
}
};
B().MakeA().DoSomething();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.