func

How do I declare a Func Delegate which returns a Func Delegate of the same type?

隐身守侯 提交于 2020-01-02 01:00:10
问题 I'd like to write a method which does some work and finally returns another method with the same signature as the original method. The idea is to handle a stream of bytes depending on the previous byte value sequentially without going into a recursion. By calling it like this: MyDelegate executeMethod = handleFirstByte //What form should be MyDelegate? foreach (Byte myByte in Bytes) { executeMethod = executeMethod(myByte); //does stuff on byte and returns the method to handle the following

Convert Func<T, String> to Func<T, bool>

断了今生、忘了曾经 提交于 2020-01-02 00:54:08
问题 I think my mind is exploding trying to figure out Funcs... If this makes no sense, I apologize, right now it make sense to me but its been a long day already .... 1) Assuming you are given a func which takes in T and outputs a string: Func<T, string> Can you transform that into a func that take in a T and returns a bool based on some logic (in this case if the returned string is empty (String.IsNullOrWhiteSpace)? Func<T, bool> 2) Can you do the same thing if you are given an Expression<Func<T

Invoking Actions from Moq

北城余情 提交于 2020-01-01 06:43:13
问题 I've got a service with a method that takes two Action s, one for success and one for failure. Each Action takes a Result parameter that contains additional information... void AuthoriseUser(AuthDetails loginDetails, Action<AuthResult> onSuccess, Action<AuthResult> onFailure); I'm writing a unit test for a class that is dependant on that service, and I want to test that this class does the correct things in the onSuccess(...) and onFailure(...) callbacks. These are either private or anonymous

How to pass a method with multiple parameters as argument of another method

与世无争的帅哥 提交于 2019-12-25 06:04:20
问题 I have multiple and different methods that I can't edit: Public Function Test1(A As Integer, B As String, C As Boolean) As Boolean Public Function Test2(A As Boolean, B As Double) As DataTable Public Function Test3(A As String) As Integer I started creating a class like this: Public Class MyWrapperClass Dim _method As Action() Public Sub New(Method As Action()) _method = Method End Sub Public ExecuteFunction() _method() ' And do something with the result End Function End Class The problem is:

Returning a true/false value from a Func<object, bool> implementation with an Android AlertDialog, without blocking the UI

微笑、不失礼 提交于 2019-12-24 19:18:34
问题 I have to use a function in my Xamarin project, which has a DoOperation(Func<object, bool> ConfirmOperation) overload. The object has a property, called string TextToCheck. The function should check this property, and if it meets a certain criteria, it needs to ask the user whether he wants to continue with the operation, or not. The implementation of the Func<object, bool> function that the DoOperation(Func<object, bool> ConfirmOperation) invokes in itself would go something like this in

Calling a function which is placed in an Array

痴心易碎 提交于 2019-12-24 18:43:18
问题 I have an array where I have the Title of Button as Key and the Image as Value with position 0. I am calling this in CollectionView and the view looks like show in screenshot. At position 1 i have the name of the function that needs to be called with didSelectItemAt indexPath. How do I execute the function on click? var mainBtnsArr = [ ["Hotels" : ["homepage_hotel", ShowHotelSearch]], ["Flights" : ["homepage_flights", ShowFlightSearch]], ["Transfer" : ["homepage_transfer", ShowTransferSearch]

Passing params through a Func<>

徘徊边缘 提交于 2019-12-24 00:55:29
问题 I use delegates with lambda expressions instead of methods with just one line of code like: Func<int, int, int> Add = (x, y) => x + y; int Result = Add(1, 2); // 3 Now I have the problem that I need a unknown number of parameters. Is there a was to solve it like this: Func<string, params string[], string> MergeFormat = (Look, values) => string.Format(Look, string.Join("-", values)); with params string[] the result would be string.Format(func, string.Join("-", v1, v2, v3)); //currently

State pattern using methods

你说的曾经没有我的故事 提交于 2019-12-23 18:32:53
问题 I'm trying to implement a simple state machine based on a modified version of the state pattern using methods as states instead of classes, something like this: private Action<Input> currentState; private void NextState(Input i) { currentState(i); } private void State1(Input i) { if( i ... ) currentState = State1; else currentState = State2; } private void State2(Input i) { if( i ... ) currentState = State1; else currentState = State2; } But it would be more elegant if I could do: private

How to call method with Expression of type Func as parameter

爱⌒轻易说出口 提交于 2019-12-23 18:32:04
问题 I used Repository pattern that I saw on online tutorial... Everything works fine except for find method, I have no idea how to work with this and I'm having hard time understanding Expressions or Func types. I used linq and lambda before but I'm begginer and still don't use it fluently... public IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> predicate) { return Context.Set<TEntity>().Where(predicate); } I have this model class: public partial class Artikl { [Browsable(false)]

Is there a way to capture a lambda expression so that it's not compile-time forced to take on an identity as either an Expression or Delegate type?

你离开我真会死。 提交于 2019-12-23 17:11:26
问题 Suppose I have a complex lambda expression as follows: x => x.A.HasValue || (x.B.HasValue && x.C == q) || (!x.C.HasValue && !x.A.HasValue) || //...expression goes on I want to use this as an Expression<Func<T,bool> in (e.g. Linq-To-Entities) Queryable.Where method. I also want to use it in the Enumerable.Where method, but the Where method only accepts a Func<T,bool> , not an Expression<Func<T,bool> . The lambda syntax itself can be used to generate either an Expression<Func<T,bool>> or a Func