gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:00:42 27 4
gpt4 key购买 nike

是否有等效于 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com