delegates

How to turn this Func into an expression?

為{幸葍}努か 提交于 2020-01-23 09:44:27
问题 I am playing around with expression trees and trying to better understand how they work. I wrote some sample code that I'm working with and hopefully someone can help me out. So I have this somewhat messy query: /// <summary> /// Retrieves the total number of messages for the user. /// </summary> /// <param name="username">The name of the user.</param> /// <param name="sent">True if retrieving the number of messages sent.</param> /// <returns>The total number of messages.</returns> public int

replay a list of functions and parameters

你离开我真会死。 提交于 2020-01-22 11:59:05
问题 I have a series of functions that I want to have the following functionality. When the function is called, add itself to a list of functions remembering the parameters and values Allow the list of functions to be called at a later date The different functions have a variety of different parameters and I'm struggling to think of an elegant way to do this. Any help would be appreciated. 回答1: I think this would meet your needs, however the functions are not "adding themselves". public class

problem with delegate

。_饼干妹妹 提交于 2020-01-21 15:24:50
问题 I've made this to call unmanaged function from C code. pCallback is a function pointer so on the managed side is a delegate. [DllImport("MyDLL.dll")] public static extern Result SetCallback( IntPtr handle, Delegate pCallback, CallbackType Type); Now I am setting public delegate void pfnCallback(uint PromptID, ttsEventType evt, IntPtr lData); public Form1() { pfnCallback cb = new pfnCallback(cback); (...) Wrapper.SetCallback(handle, cb, IntPtr.Zero, CallBackType.DEFAULT); (...) } It gives my

Can I use custom delegate method in Where method of Entity Framework?

我的未来我决定 提交于 2020-01-21 05:22:06
问题 Where<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate); I pass parameter to Where method as follows: f => f.Id > 4 . Can I pass a delegate method instead of f.Id > 4 ? 回答1: No. The Entity Framework needs to be able to see everything that is being attempted. So if you simply did something like this: queryable.Where(f => DelegateFunc(f)); Where the definition of DelegateFunc looks like this: public bool DelegateFunc(Foo foo) { return foo.Id > 4; } The Entity

Generic view controller won't work with delegate and extension

半世苍凉 提交于 2020-01-17 10:34:31
问题 I already posted a question but it was not clear about what I want. As @AlainT suggested, I filed a new one. I have a typealias tuple public typealias MyTuple<T> = (key: T, value: String) A protocol: public protocol VCADelegate: class { associatedtype T func didSelectData(_ selectedData: MyTuple<T>) } A view controller (VCA) with a table view class VCA<T>: UIViewController, UITableViewDelegate, UITableViewDataSource { var dataList = [MyTuple<T>]() weak var delegate: VCADelegate? // Error: can

Generic view controller won't work with delegate and extension

喜欢而已 提交于 2020-01-17 10:33:53
问题 I already posted a question but it was not clear about what I want. As @AlainT suggested, I filed a new one. I have a typealias tuple public typealias MyTuple<T> = (key: T, value: String) A protocol: public protocol VCADelegate: class { associatedtype T func didSelectData(_ selectedData: MyTuple<T>) } A view controller (VCA) with a table view class VCA<T>: UIViewController, UITableViewDelegate, UITableViewDataSource { var dataList = [MyTuple<T>]() weak var delegate: VCADelegate? // Error: can

Generic view controller won't work with delegate and extension

北城余情 提交于 2020-01-17 10:32:32
问题 I already posted a question but it was not clear about what I want. As @AlainT suggested, I filed a new one. I have a typealias tuple public typealias MyTuple<T> = (key: T, value: String) A protocol: public protocol VCADelegate: class { associatedtype T func didSelectData(_ selectedData: MyTuple<T>) } A view controller (VCA) with a table view class VCA<T>: UIViewController, UITableViewDelegate, UITableViewDataSource { var dataList = [MyTuple<T>]() weak var delegate: VCADelegate? // Error: can

Member reference base type 'Class' is not a structure or union - has the Fixit led me in the right direction?

心已入冬 提交于 2020-01-17 08:30:11
问题 I’m trying to make a delegate that will send messages from UIButtons within a custom UIView called SGView and am a bit out of my depth following the error messages. I recently learned how to get a delegate to send messages successfully from within an instance method. SGView includes a class method that arranges multiple UIButtons in a circle and was designed to be used by different UIViews. The geometry works when the method is called from a parent UIView. I have now declared the delegate by

UIView setDelegate:]: unrecognized selector sent to instance

本秂侑毒 提交于 2020-01-17 05:03:30
问题 I am new to IOS, and Trying to pass two values form a UIViewController to a UIView. I followed few examples,some posts, tried and still no luck. I am getting this error while running the application. The error is .. [MenuComponent setDelegate:]: unrecognized selector sent to instance MenuComent is My UIView. FullVC is my UIViewController. FullVC.h @class FullVC; @protocol MenuComponentDelegate <NSObject> -(void)shareToView:(NSString *)titleString inUrl:(NSString *)urlString; @end @interface

Using Delegates in multiple view controllers

大憨熊 提交于 2020-01-16 14:44:51
问题 I am using multiple view controllers and trying the link the UITextfield in one view controller to the label in another view controller using delegate. ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UITextFieldDelegate> { IBOutlet UITextField *txtField; } @end ViewController.m #import "ViewController.h" #import "ViewController2nd.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any