s MethodBase.GetCurrentMethodと同等のポータブルクラスライブラリはありますか?
私はPCLを初めて使用します。PCLを使用して、Silverlightで確実に使用され、他の場所で使用される可能性のあるクライアントコードを保持できるかどうかを調べています。ソースをスキャンすると、PCLには存在しないように見えるMethodBase.GetCurrentMethodへの呼び出しがたくさん表示されます。
** 編集 **
問題のライブラリからこのサンプルをリッピングしました。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) }
)
);
}
}
}