how can i store and reuse pieces of my lambda expressions

前端 未结 3 993
谎友^
谎友^ 2021-02-19 19:18

I have a block of code where a piece of the lambda expression is used again and again. How can store this logic so that i can reuse this expression piece?

Eg: lets take

3条回答
  •  攒了一身酷
    2021-02-19 20:14

    Func func = (map => ((((map.User.Key ==_users.PublicUser.Key || map.User.Key == _users.CurrentUser.Key) && map.AccessLevel.ToAccessLevel() == AccessLevel.Read)).Count() > 0));
    

    EDIT:

    you could try something like this.

    class MyClass{
    
     Func func = null;
    
     MyClass()
     {
        func = (map => ((((map.User.Key ==_users.PublicUser.Key || map.User.Key == _users.CurrentUser.Key) && map.AccessLevel.ToAccessLevel() == AccessLevel.Read)).Count() > 0));
      }
      ...
      ...
    }
    

提交回复
热议问题