Portable Class Library equivalent to MethodBase.GetCurrentMethod
s there Portable Class Library equivalent to MethodBase.GetCurrentMethod?
I'm new to PCLs. I'm justing looking into whether I can use a PCL to hold some client code that will definitely be used on Silverlight and may be used elsewhere. Having scanned the source, I can see plenty of calls to MethodBase.GetCurrentMethod which doesn't seem to exist in the PCL.
** EDIT **
I've ripped this sample out of the library in question. IsNullOrEmpty() was using String.IsNullOrWhiteSpace(String) which doesn't seem to be available, so that bit's a 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) }
)
);
}
}
}
(I 'own' the Portable Library project at Microsoft)
We don't expose it in PCL because it's not supported in Windows 8 .NET for Metro apps. What's your usage of this method?
链接地址: http://www.djcxy.com/p/68850.html