我需要你的帮助。我尝试并努力将此代码转换为vb.net,但我不能。即使我使用了多个代码转换器,但结果是两行代码出错。
以下是c#代码:
public List<T> SortByPropertyName(string propertyName, bool ascending)
{
//Create a Lambda expression to dynamically sort the data.
var param = Expression.Parameter(typeof(T), "N");
var sortExpresseion = Expression.Lambda<Func<T, object>>
(Expression.Convert(Expression.Property(param, propertyName), typeof(object)), param);
if (ascending)
{
return this.AsQueryable<T>().OrderBy<T, object>(sortExpresseion).ToList<T>();
}
else
{
return this.AsQueryable<T>().OrderByDescending<T, object>(sortExpresseion).ToList<T>();
}
}
以下是VB转换代码
Public Function SortByPropertyName(propertyName As String, ascending As Boolean) As List(Of T)
'Create a Lambda expression to dynamically sort the data.
Dim param = Expression.Parameter(GetType(T), "N")
Dim sortExpresseion = Expression.Lambda(Of Func(Of T, Object))(Expression.Convert(Expression.[Property](param, propertyName), GetType(Object)), param)
If ascending Then
Return Me.AsQueryable(Of T)().OrderBy(Of T, Object)(sortExpresseion).ToList(Of T)()
Else
Return Me.AsQueryable(Of T)().OrderByDescending(Of T, Object)(sortExpresseion).ToList(Of T)()
End If
End Function
我无法解析的两行代码是IF ELSE条件中的行。
谢谢
我找到了以下代码,我将尝试一下。它位于以下链接中: http://p2p.wrox.com/book-asp-net-3-5-enterprise-application-development-visual-studio-2008-problem-design-solutio/73626-page-107-converting-vbulletin-net.html