Portable Class Library equivalent to MethodBase.GetCurrentMethod

左心房为你撑大大i 提交于 2019-12-10 13:32:24

问题


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) }
                    )
                );
        }
    }
}

回答1:


(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?



来源:https://stackoverflow.com/questions/8657744/portable-class-library-equivalent-to-methodbase-getcurrentmethod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!