자신 만의 표현식을 작성하고 컴파일하거나 AsQueryable을 사용하는 경우 예; LINQ로 생성 된 메서드는 디버깅 할 때 고질적 인 문제가됩니다.
당신은
실제 방법의 작은 fragements를 사용하여 약간의 고통을 절약 할 수 있습니다
- 스택 추적에 표시됩니다 유용한 적어도 뭔가를 ...
또 다른 고려 사항은 다음과 같습니다 오히려 하나 개의 거대한 표현을하는 것보다, 당신이 할 수있는 경우 데이지 - 체인 (daisy-chain) 일을 좀 더하면 스택 트레이스에서 더 많은 아이디어를 얻을 수있다. 단점은 성능입니다. Where (foo) .Where (bar)는 두 개의 대리자 호출이며 where-as (foo & & bar)는 하나 일 수 있습니다.
확장 옵션의 디버그 버전에서 스왑하는 것이 하나의 옵션 일 수 있습니다. 같은 공간에있는 IQueryable<T>
및 Queryable
...이 있지만, 작동하기 때문에 불행하게도 그것은 약간의 불편은
출력 처음입니다 ... :
이
>Where: x => ((x % 2) = 0)
<Where: x => ((x % 2) = 0)
>Count
'WindowsFormsApplication2.vshost.exe' (Managed): Loaded 'Anonymously Hosted DynamicMethods Assembly'
<Count
코드 :
using System;
using System.Diagnostics;
using System.Linq.Expressions;
namespace Demo
{
using DebugLinq;
static class Program
{
static void Main()
{
var data = System.Linq.Queryable.AsQueryable(new[] { 1, 2, 3, 4, 5 });
data.Where(x => x % 2 == 0).Count();
}
}
}
namespace DebugLinq
{
public static class DebugQueryable
{
public static int Count<T>(this System.Linq.IQueryable<T> source)
{
return Wrap(() => System.Linq.Queryable.Count(source), "Count");
}
public static System.Linq.IQueryable<T> Where<T>(this System.Linq.IQueryable<T> source, Expression<Func<T, bool>> predicate)
{
return Wrap(() => System.Linq.Queryable.Where(source, predicate), "Where: " + predicate);
}
static TResult Wrap<TResult>(Func<TResult> func, string caption)
{
Debug.WriteLine(">" + caption);
try
{
TResult result = func();
Debug.WriteLine("<" + caption);
return result;
}
catch
{
Debug.WriteLine("!" + caption);
throw;
}
}
}
}
Linq to 개체는 일반적으로 System.Linq.Enumerable의 메서드를 참조합니다. 동적 메서드는 포함하지 않지만 익명 메서드가 포함될 수 있습니다. 당신은 정말로 동적 인 방법을 사용하고 있습니까? –
@David - 나는 같은 질문을했다. Orlangur는 AsQueryable을 사용하여 여러 소스에서 동일한 코드를 사용하므로 동적 방법이 필요합니다. –