1

내 VS LIGHTSWITCH 2013 포털 응용 프로그램에서 다른 내부 앱에 링크되는 타일을 만들 수 있습니다. 새 타일이 작성되면 이름이 'TileTitle + "User"'인 역할이 작성됩니다. 이렇게하면 사용자 역할에 따라 타일을 표시하거나 숨길 수 있습니다. 그러나 쿼리 필터 메서드에서 타일 엔터티를 필터링 할 때 IsInRole 메서드를 사용할 수 없다는 오류가 발생합니다. Expression Tree에서 오류가 발생했습니다

는 뒷조사 후 나는 식 트리를 사용해보기로 결정,이 내가 생각 해낸 것입니다 : 그러나 작동하지 않습니다

partial void TileLinks_Filter(ref Expression<Func<TileLink, bool>> filter) 
{ 
    ParameterExpression p = Expression.Parameter(typeof(TileLink), "e"); 
    MemberExpression ti = Expression.Property(p, "Title"); 
    MethodInfo m2 = typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) }); 


    Type t = this.Application.User.GetType(); 
    MethodInfo m = t.GetMethod("IsInRole"); 

    Expression filterExpression = Expression.IsTrue(Expression.Call(Expression.Call(m2, ti, Expression.Constant(" User")), m)); 

    filter = Expression.Lambda<Func<TileLink, bool>>(filterExpression, p); 

    // e => this.Application.User.IsInRole(e.Title + " User"); 
    // this is what I would like to do 
} 

이, 나는이 아주 이상한 오류 메시지와 함께 왼쪽입니다.

Method 'Boolean IsInRole(System.String)' declared on type 'System.Security.Claims.ClaimsPrincipal' cannot be called with instance of type 'System.String' 

동적으로 생성 된 역할을 기반으로 데이터를 필터링하는 데 도움주세요!

답변

0

Expression.Call 외선 통화에서 인수가 취소되었습니다. 당신이 조금 밖으로 코드를 부러 경우,이로 끝날 것 : 이것은에 IsInRole를 호출하는 객체 인스턴스로 e.Title + "User"를 사용하도록 지시한다

var titlePlusUser = Expression.Call(m2, ti, Expression.Constant(" User")); 
var isInRole = Expression.Call(titlePlusUser, m); // <<-- !!! 
Expression filterExpression = Expression.IsTrue(isInRole); 

.

대신 this.Application.User을 얻는 방법을 알고있는 다른 표현식을 생성하고 첫 번째 매개 변수로 해당 표현식을 전달해야합니다.

var isInRole = Expression.Call(applicationUser, m, titlePlusUser);