2011-12-28 39 views
6

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

需要PCL的設備將在2013年夏季纔會出現。也許有足夠的時間來弄清楚如何放棄不支持的方法? GetCurrentMethod()當然不應該是一個重要的遺漏。 – 2011-12-28 20:54:00

回答

1

(我自己的'微軟的便攜式庫項目)

我們不PCL揭露它,因爲它不是在Windows 8的.NET支持的地鐵應用程序。這種方法的用法是什麼?

+0

我已更新原始問題以包含樣本。原始庫中有許多類似的擴展方法。 – ssg31415926 2012-02-21 16:19:37

+1

嗨大衛...我正在尋找使用GetCurrentMethod純粹是爲了添加到調試日誌記錄,很像C _ _FUNCTION_ _宏。有沒有其他方法可以在PCL .NET中實現這一點? – GrahamW 2012-11-08 17:23:53

+4

這種方法缺失是一件壞事。這對於將記錄輸入到共享庫至關重要。瞭解當前的方法可以確保您的日誌代碼記錄所有輸入參數。方法簽名更改時非常重要。 – Daniel 2014-06-23 19:25:47