delegates

Convert C# statement body lambda to VB

淺唱寂寞╮ 提交于 2019-12-20 03:20:34
问题 It appears that VB in VS8 doesn't support/convert lambda expressions with a statement body. I'm using them in my C# application, but now must convert it to VB. I'm creating a whole bunch of controls dynamically, and I want to be able to give them event handlers on the fly. This is so I can build a dynamic user interface from a database. In the following code I'll create a form and a checkbox, make the checkbox control the form's visibility, add a few method handlers to the form, and then add

How do I cast an event handler delegate to one with a different signature

回眸只為那壹抹淺笑 提交于 2019-12-20 02:44:07
问题 The code I am writing is actually a WPF behaviour to get the selected items from a grid control (SelectedItems, as we know, is not a bindable property). I am actually using a Telerik RadGridView but I would like the Behaviour to be general for anything with a SelectionChanged event. However, different controls have different signatures for the SelectionChanged event handlers (RadGridView uses Telerik.Windows.Controls.SelectionChangeEventArgs whereas a standard GridView uses System.Windows

Using reflection to specify the type of a delegate (to attach to an event)?

╄→гoц情女王★ 提交于 2019-12-20 02:26:19
问题 What I effectively want to do is something like this (I realise this is not valid code): // Attach the event. try { EventInfo e = mappings[name]; (e.EventHandlerType) handler = (sender, raw) => { AutoWrapEventArgs args = raw as AutoWrapEventArgs; func.Call(this, args.GetParameters()); }; e.AddEventHandler(this, handler); } ... Now I know that the e.EventHandlerType will always derive from EventHandler<AutoWrapEventArgs>. However, I can't just do: EventHandler<AutoWrapEventArgs> handler =

Extending a delegate from a base class

隐身守侯 提交于 2019-12-19 21:18:09
问题 I have an objc base class: @protocol BaseClassDelegate; @interface BaseClass : NSObject @property (nonatomic, weak) id <BaseClassDelegate> delegate; @end @protocol BaseClassDelegate <NSObject> -(void)baseDelegateMethod; @end I am creating a swift sub-class in which I want to extend my delegate... protocol SubClassDelegate : BaseClassDelegate { func additionalSubClassDelegateMethod(); } class SubClass: BaseClass { @IBAction func onDoSomething(sender: AnyObject) { delegate?

Action delegate in .NET2 - Using the generic type 'System.Action<T>' requires '1' type arguments

被刻印的时光 ゝ 提交于 2019-12-19 19:51:59
问题 I'm porting working code from .NET4 to .NET2 (a WinCE device). The usage of Action taking no arguments and returning no value isn't allowed in .NET2 compile error on line 5 below: Using the generic type 'System.Action' requires '1' type arguments Workaround thoughts? //first state is the default for the system public enum States { EnterVoucherCode, EnterTotalSale, ProcessVoucher }; public enum Events { PressNext, PressRedeem, ProcessSuccess, ProcessFail, PressBackToVoucherCode }; public

C#: what's the difference between SomeEvent += Method and SomeEvent += new Delegate(Method) [duplicate]

China☆狼群 提交于 2019-12-19 18:25:27
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Should I Create a New Delegate Instance? Hi, I've tried searching for the answer to this, but don't really know what terms to search for, and none of the site-suggested questions are relevant. I'm sure this must have been answered before though. Basically, can somebody tell me what's the difference between these two lines in C#: SomeEvent += SomeMethod SomeEvent += new SomeDelegate(SomeMethod) For example:

C#: what's the difference between SomeEvent += Method and SomeEvent += new Delegate(Method) [duplicate]

别等时光非礼了梦想. 提交于 2019-12-19 18:25:03
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Should I Create a New Delegate Instance? Hi, I've tried searching for the answer to this, but don't really know what terms to search for, and none of the site-suggested questions are relevant. I'm sure this must have been answered before though. Basically, can somebody tell me what's the difference between these two lines in C#: SomeEvent += SomeMethod SomeEvent += new SomeDelegate(SomeMethod) For example:

How to get results list of delegate's invocation?

怎甘沉沦 提交于 2019-12-19 17:42:32
问题 Let say, I have a MulticastDelegate that implements generic delegate and contains several calls: Func<int> func = null; func += ( )=> return 8; func += () => return 16; func += () => return 32; Now this code will return 32: int x = func(); // x=32 I would like to know if there exists (or better I should ask why it doesn't exist!) the C# language feature using which is possible to get the access to results of all delegate's invocations, that means to get the list ({8,16,32})? Of course it's

WPF/MVVM: Delegating a domain Model collection to a ViewModel

耗尽温柔 提交于 2019-12-19 11:43:27
问题 A domain model collection (normally a List or IEnumerable) is delegated to a ViewModel. Thats means my CustomerViewModel has a order collection of type List or IEnumerable. No change in the list is recognized by the bound control. But with ObservableCollection it is. This is a problem in the MVVM design pattern. How do you cope with it? UPDATE : Sample of how I do it: public class SchoolclassViewModel : ViewModelBase { private Schoolclass _schoolclass; private ObservableCollection

Swift, for some UIViews to their overall controller when clicked

谁说胖子不能爱 提交于 2019-12-19 11:32:30
问题 I have a DotBoss:UIViewController There are a dozen UIView in the scene, Dot:UIView (Some are direct subviews, some are further down.) There are even container views in the chain between the highest controller and the Dot items. The dozen Dot items know if they are tapped... class Dot:UIView { private var tap:UITapGestureRecognizer? = nil override func awakeFromNib() { tap = UITapGestureRecognizer(target:self, action: #selector(SnapDot.handleTap(_:))) self.addGestureRecognizer(tap!) } func