等效于MethodBase.GetCurrentMethod的便携式类库LibraryBase.GetCurrentMethod
s便携式类库相当于MethodBase.GetCurrentMethod?等效于MethodBase.GetCurrentMethod的便携式类库LibraryBase.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支持的地铁应用程序。这种方法的用法是什么?
我已更新原始问题以包含样本。原始库中有许多类似的扩展方法。 – ssg31415926 2012-02-21 16:19:37
嗨大卫...我正在寻找使用GetCurrentMethod纯粹是为了添加到调试日志记录,很像C _ _FUNCTION_ _宏。有没有其他方法可以在PCL .NET中实现这一点? – GrahamW 2012-11-08 17:23:53
这种方法缺失是一件坏事。这对于将记录输入到共享库至关重要。了解当前的方法可以确保您的日志代码记录所有输入参数。方法签名更改时非常重要。 – Daniel 2014-06-23 19:25:47
需要PCL的设备将在2013年夏季才会出现。也许有足够的时间来弄清楚如何放弃不支持的方法? GetCurrentMethod()当然不应该是一个重要的遗漏。 – 2011-12-28 20:54:00