.net - 等价于 MethodBase.GetCurrentMethod 的可移植类库

标签 .net system.reflection portable-class-library

是否有等效于 MethodBase.GetCurrentMethod 的可移植类库?

我是 PCL 的新手。我只是在研究是否可以使用 PCL 来保存一些肯定会在 Silverlight 上使用并且可能会在其他地方使用的客户端代码。扫描了源代码后,我可以看到大量对 MethodBase.GetCurrentMethod 的调用,这在 PCL 中似乎不存在。

** 编辑 **

我已经从有问题的图书馆中删除了这个样本。 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) }
                    )
                );
        }
    }
}

最佳答案

(我“拥有”微软的可移植库项目)

我们不会在 PCL 中公开它,因为 Windows 8 .NET 不支持 Metro 应用程序。你这个方法的用途是什么?

关于.net - 等价于 MethodBase.GetCurrentMethod 的可移植类库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8657744/

相关文章:

c# - 如何通过反射获得 protected 内部方法

c# - 为什么我们需要反射?

c# - 在windows phone项目中使用可移植类库

c# - 跨 .Net 平台序列化 TypeInfo/Type

c# - 在 c# asp.net 中获取列表框的选定值

.net - 按用户设置输出路径

c# - .Net 4 中这种巨大的性能差异背后的原因是什么

c# - 当您正在测试的类在 C# 中使用反射时如何使用假货进行单元测试

C#:如何调用在另一个线程内的 if 语句中返回类型的函数?

c# - BouncyCaSTLe 未定义长度 ASN1