s Thư viện lớp học di động có tương đương với MethodBase.GetCurrentMethod không?Thư viện lớp di động tương đương với MethodBase.GetCurrentMethod
Tôi mới tham gia PCL. Tôi chỉ đang xem xét liệu tôi có thể sử dụng PCL để giữ một số mã máy khách chắc chắn sẽ được sử dụng trên Silverlight và có thể được sử dụng ở nơi khác không. Sau khi quét nguồn, tôi có thể thấy nhiều cuộc gọi đến MethodBase.GetCurrentMethod mà dường như không tồn tại trong PCL.
** EDIT **
Tôi đã xé mẫu này ra khỏi thư viện trong câu hỏi. IsNullOrEmpty() đã sử dụng String.IsNullOrWhiteSpace (String) mà dường như không có sẵn, do đó bit là một fudge.
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) }
)
);
}
}
}
Thiết bị yêu cầu PCL sẽ không xuất hiện cho đến mùa hè năm 2013. Có thể đủ thời gian để tìm ra cách từ bỏ các phương pháp không được hỗ trợ? GetCurrentMethod() chắc chắn không nên là một thiếu sót quan trọng. –