Strategy to: Attach a Delegate Utilizing Expression. Get an example from the delegate, with the CreateDelegate strategy.

postado em: Foot Fetish Dating sites | 0

Strategy to: Attach a Delegate Utilizing Expression. Get an example from the delegate, with the CreateDelegate strategy.

If you use picture to load and operated assemblies, you will not need vocabulary properties like the C# += user and also the Visual plain AddHandler report to connect events. In this article surgery reveal ideas hook-up a preexisting approach to a meeting by getting every needed kinds through expression, and how to build a dynamic approach using picture emit and catch it to a conference.

For the next technique to hook up an event-handling delegate, watch code instance for its AddEventHandler method for the EventInfo type.

To connect a delegate making use of expression

Bunch a system which has a kind that lifts parties. Assemblies are usually laden up with the system.Load way. To help keep this situation straightforward, a derived form in the current set up is employed, so that the GetExecutingAssembly technique is used to fill the current set-up.

Create a kind target presenting the character, and produce an instance of this type. The CreateInstance(sort) technique is used in the following code considering that the form offers a parameterless constructor. There are numerous various other overloads of this CreateInstance approach that can be used if the type you are produce won’t have a parameterless constructor. This case happens to be accumulated as means subject to retain the literary composition that nothing is recognized on the forum. (Reflection enables you to get your kinds in an assembly with no knowledge of their own manufacturers in advance.)

Become an EventInfo target representing case, and make use of the EventHandlerType residential property to receive the particular delegate utilized to deal with the big event. Inside the next signal, an EventInfo the touch occasion try obtained.

Receive a MethodInfo target stage the tactic that takes care of in case. The complete system laws through the illustration segment afterwards in this particular subject matter has one way that meets the signature with the EventHandler delegate, which takes care of 1 click show, but you can in addition generate active means at powered moments. For data, your accompanying method, for creating a conference handler at go moments through a dynamic means.

This approach try stationary ( Shared in Visual vital), as a result delegate type must certanly be supplied. Making use of overloads of CreateDelegate that need a MethodInfo is preferred.

Take advantage of the include accessor technique and invoke they to get together in case. All occasions have got a put accessor and a remove accessor, and those are hidden by way of the syntax of high-level dialects. Case in point, C# employs the += driver to hook-up happenings, and Visual Essential uses the AddHandler account. The next laws has got the add accessor with the hit event and invokes it late-bound, moving inside the delegate example. The reasons must certanly be passed as a range.

Check the expensive vacation event. Listed here laws displays the design outlined in rule example. Clicking the shape creates case handler.

To create a conference handler at streak efforts through a compelling strategy

Event-handler techniques may be made at extend occasion, using lightweight compelling options and expression release. To build an event handler, you’ll need the repay form and parameter types the delegate. These may get received by test the delegate’s produce system. In this article signal makes use of the GetDelegateReturnType and GetDelegateParameterTypes methods to receive these details. The laws of these approaches come in the Example area later on in this area.

It’s not at all required to label a DynamicMethod, as a result clear string can be employed. In following laws, the last argument acquaintances the dynamic strategy making use of the recent sort, giving the delegate access to the community and private members of the instance type.

Produce an approach human anatomy. This method loads a string, phone calls the overload for the MessageBox.Show process that takes a line, pops the repay worth from the collection (because handler does not have return form), and results. To understand more about emitting compelling approaches, observe to: understand and Execute enthusiastic strategies.

Finish the active process by calling its CreateDelegate means. Use the apply accessor to add the delegate around the invocation variety when it comes to celebration.

Check case. The following laws tons the design defined in laws situation. Clicking on the proper execution evoke the predetermined function handler along with emitted occasion handler.

Illustration

In this article rule situation shows ideas hook up a preexisting technique to gay foot fetish dating an occasion utilizing expression, together with utilizing the DynamicMethod type to emit one way at work some time and connect it to a conference.

Deixe uma resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *