當我運行這個C#代碼時,沒有問題......但是當我將它翻譯成VB.NET時,它會編譯但由於'CompareString'成員不被允許在表達式中而受到打擊......我覺得我錯過了一些東西這裏的關鍵...VB.NET中的lambda表達式...我做錯了什麼?
private void PrintButton_Click(object sender, EventArgs e)
{
if (ListsListBox.SelectedIndex > -1)
{
//Context
using (ClientOM.ClientContext ctx =
new ClientOM.ClientContext(UrlTextBox.Text))
{
//Get selected list
string listTitle = ListsListBox.SelectedItem.ToString();
ClientOM.Web site = ctx.Web;
ctx.Load(site,
s => s.Lists.Where(l => l.Title == listTitle));
ctx.ExecuteQuery();
ClientOM.List list = site.Lists[0];
//Get fields for this list
ctx.Load(list,
l => l.Fields.Where(f => f.Hidden == false
&& (f.CanBeDeleted == true || f.InternalName == "Title")));
ctx.ExecuteQuery();
//Get items for the list
ClientOM.ListItemCollection listItems = list.GetItems(
ClientOM.CamlQuery.CreateAllItemsQuery());
ctx.Load(listItems);
ctx.ExecuteQuery();
// DOCUMENT CREATION CODE GOES HERE
}
MessageBox.Show("Document Created!");
}
}
但在VB.NET代碼這個錯誤是由於在ctx.Load()方法沒有被允許 'CompareString' 會員...
Private Sub PrintButton_Click(sender As Object, e As EventArgs)
If ListsListBox.SelectedIndex > -1 Then
'Context
Using ctx As New ClientOM.ClientContext(UrlTextBox.Text)
'Get selected list
Dim listTitle As String = ListsListBox.SelectedItem.ToString()
Dim site As ClientOM.Web = ctx.Web
ctx.Load(site, Function(s) s.Lists.Where(Function(l) l.Title = listTitle))
ctx.ExecuteQuery()
Dim list As ClientOM.List = site.Lists(0)
'Get fields for this list
ctx.Load(list, Function(l) l.Fields.Where(Function(f) f.Hidden = False AndAlso (f.CanBeDeleted = True OrElse f.InternalName = "Title")))
ctx.ExecuteQuery()
'Get items for the list
Dim listItems As ClientOM.ListItemCollection = list.GetItems(ClientOM.CamlQuery.CreateAllItemsQuery())
ctx.Load(listItems)
' DOCUMENT CREATION CODE GOES HERE
ctx.ExecuteQuery()
End Using
MessageBox.Show("Document Created!")
End If
End Sub
試過.Equals,我得到一個運行時錯誤,這不支持... – Bob 2010-03-10 05:15:25
事實上,所有字符串操作似乎都不支持,這是奇怪的考慮到比較中的兩個項目都是字符串。 .. – Bob 2010-03-10 05:15:54