delegates

How to XML serialize and deserialize an instance of Dictionary <type, List<Action<T>>>?

情到浓时终转凉″ 提交于 2019-12-25 06:55:26
问题 I want to serialize and deserialize my dictionary object of type Dictionary <type, List<Action<T>>> . I tried using XMLserializer - it fails. Cannot serialize member MyClass.MyDictionary of type System.Collections.Generic.Dictionary‘2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], because it implements IDictionary. I am using .NET framework 4.0. What is

Converting using SqlConnection to Func delegate

旧时模样 提交于 2019-12-25 05:34:15
问题 I have the following code that is being copied and pasted in a number of places. The only difference being that there is a single call in the middle of the usings which changes. So I made a public MyEntity Read(int id) { using (SqlConnection sqlConn = new SqlConnection(ConnectionString)) { sqlConn.Open(); return MyDataLayer.Select(sqlConn, id); } } So I came up with this. However, my problem is how do i pass the sqlConn var to the call? public TResult UsingSqlConnection<TResult>(Func<TResult>

Access object from other thread [duplicate]

瘦欲@ 提交于 2019-12-25 05:25:38
问题 This question already has answers here : How do I update the GUI from another thread? (47 answers) Closed 4 years ago . I'm trying to be able to access some controls in my main form from an other thread. Let's consider this picture: I want to Instantiate that control (It's a panel in my case) into the second thread. My problem is that i have found a LOT of answers that just modifies a control (Set the text of a textbox for instance) and not be able to read/write it's properties like it's an

Delegate in UISplitView not being called

左心房为你撑大大i 提交于 2019-12-25 05:10:03
问题 I've set up a delegate methos to communicate from my masterViewController to my detailViewController but the delegate method isn't getting called. MasterViewController.h #import <UIKit/UIKit.h> @class DetailViewController; @class MasterViewController; @protocol MasterViewControllerDelegate - (void)SelectionChanged:(NSString *)url; @end @interface MasterViewController : UITableViewController @property (nonatomic, weak) id<MasterViewControllerDelegate> delegate; @property (strong, nonatomic)

Ambiguous call on an Action<T> where T inherits 2 interfaces having the same method signature

…衆ロ難τιáo~ 提交于 2019-12-25 04:59:20
问题 I have the following code: public class MyClass { public void MyMethod() { Action<Child> aFoo = a => a.Foo(); } } interface Parent1 { void Foo(); } interface Parent2 { void Foo(); } interface Child : Parent1, Parent2 { } However, the compiler tells me that I have an ambiguous call on aFoo . I tried to do Action<Child> aFoo = (A a) => a.Foo(); but it tells me that I cannot convert lambda expression to delegate type System.Action<Child> How do I resolve the error of ambiguity? 回答1: By casting

How to implement delegate in place of notification

╄→尐↘猪︶ㄣ 提交于 2019-12-25 04:46:19
问题 ## NetworkClass -(void)getResponse:(NSString *)url{ NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; [urlRequest setHTTPMethod:@"GET"]; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration]; NSURLSessionDataTask *task = [session dataTaskWithRequest: urlRequest completionHandler:^(NSData *data, NSURLResponse *response,

Passing information to a custom TableViewCell - Swift

こ雲淡風輕ζ 提交于 2019-12-25 04:32:36
问题 The problem is this: I tried many ways to pass down information to a ViewController1 from a SecondViewController. In this first ViewController1 I have a tableView, and in this tableView, each cell will receive an image and a label. What I want to do is, in the SecondViewController, I will write something in a textField and pick some random image and display it in the ViewController1. Could someone tell me how to do it? I tried delegates, dequeuereusablecell and the data won't display in the

Clever event accessors - to fire handlers on the thread they were registered?

丶灬走出姿态 提交于 2019-12-25 03:52:37
问题 Have just had an idea, I haven't seen it before, wondering if you guys thought it was a good idea, if it exists, any common pitfalls etc. - and also how to implement it. There are several times I've found myself subscribing to an event from the UI thread that will be called from a different thread - for example, notification of a service call completing. 'My' idea would be to store the current Dispatcher in the add block along with the handler delegate, then when the event is 'fired', perform

Clever event accessors - to fire handlers on the thread they were registered?

风流意气都作罢 提交于 2019-12-25 03:51:07
问题 Have just had an idea, I haven't seen it before, wondering if you guys thought it was a good idea, if it exists, any common pitfalls etc. - and also how to implement it. There are several times I've found myself subscribing to an event from the UI thread that will be called from a different thread - for example, notification of a service call completing. 'My' idea would be to store the current Dispatcher in the add block along with the handler delegate, then when the event is 'fired', perform

Which is faster to use binding using converter or update in a property changed callback?

こ雲淡風輕ζ 提交于 2019-12-25 03:28:30
问题 I need fast updates, so I was wondering which one is faster and more efficient. 回答1: I performed some measurements, and can proclaim, that using a converter in a binding is cheaper than not using it. We're talking about 9% time saving. Probably, finding / creating a default converter takes more time than taking an instance of a converter from a resource... 来源: https://stackoverflow.com/questions/8872600/which-is-faster-to-use-binding-using-converter-or-update-in-a-property-changed-c