s便攜式類庫相當於MethodBase.GetCurrentMethod?等效於MethodBase.GetCurrentMethod的便攜式類庫LibraryBase.GetCurrentMethod
我是PCL的新手。我正在考慮是否可以使用PCL來保存一些客戶端代碼,這些客戶端代碼一定會在Silverlight上使用,並可能在其他地方使用。掃描了源代碼後,我可以看到很多對MethodBase.GetCurrentMethod的調用,它似乎不存在於PCL中。
**編輯**
我撕開這個樣品出來有問題的庫。 IsNullOrEmpty()使用String.IsNullOrWhiteSpace(String),它似乎不可用,所以這是一個騙局。
using System;
using System.Linq;
using System.Reflection;
using System.Linq.Expressions;
namespace LinqToLdap.PCL
{
public static class QueryableExtensions
{
internal static bool IsNullOrEmpty(this String str)
{
return string.IsNullOrEmpty(str);
}
public static IQueryable<TSource> FilterWith<TSource>(this IQueryable<TSource> source, string filter)
{
if (source == null) throw new ArgumentNullException("source");
if (filter.IsNullOrEmpty()) throw new Exception("Filters cannot be null, empty, or white-space.");
if (!filter.StartsWith("("))
{
filter = "(" + filter + ")";
}
return source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
((MethodInfo)MethodBase.GetCurrentMethod())
.MakeGenericMethod(new[] { typeof(TSource) }),
new[] { source.Expression, Expression.Constant(filter) }
)
);
}
}
}
需要PCL的設備將在2013年夏季纔會出現。也許有足夠的時間來弄清楚如何放棄不支持的方法? GetCurrentMethod()當然不應該是一個重要的遺漏。 – 2011-12-28 20:54:00