2011-12-28 11 views
6

거기 PortableBase.GetCurrentMethod와 동등한 Portable Class Library?MethodBase.GetCurrentMethod와 동등한 포터블 클래스 라이브러리

저는 PCL을 처음 사용합니다. PCL을 사용하여 Silverlight에서 사용할 클라이언트 코드를 보유 할 수 있는지 여부를 조사하고 있습니다. 다른 곳에서도 사용할 수 있습니다. 소스를 스캔하면 PCL에 존재하지 않는 것 같이 보이는 MethodBase.GetCurrentMethod에 대한 많은 호출을 볼 수 있습니다.

** 수정 ** 내가 문제의 라이브러리에서이 샘플을 찢어했습니다

. 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()가 중요한 생략 일 수는 없습니다. –

답변

1

가 메트로 애플 리케이션을위한 윈도우 8 .NET에서 지원되지 않는 때문에 우리는 PCL에 노출시키지 마십시오 (I 마이크로 소프트의 휴대용 라이브러리 프로젝트 '소유'). 이 방법을 어떻게 사용합니까?

+0

샘플을 포함하도록 원래 질문을 업데이트했습니다. 원래의 라이브러리에는 여러 가지 유사한 확장 메소드가 있습니다. – ssg31415926

+1

안녕 데이비드 ... 나는 C# _FUNCTION_ _ 매크로처럼 디버깅 로깅을 추가하기 위해 GetCurrentMethod를 사용했다. PCL .NET에서 이것을 달성 할 다른 방법이 있습니까? – GrahamW

+4

이 방법은 실망 스럽습니다. 이는 공유 라이브러리에 입력을 로깅하는 데 중요합니다. 현재 방법을 알면 로깅 코드가 모든 입력 매개 변수를 로깅하는지 확인할 수 있습니다. 메소드 서명이 변경 될 때 매우 중요합니다. – Daniel