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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With