Page MenuHomePhabricator

csharp: Generate default event implementations in Eo interfaces for dotnet.
Needs ReviewPublic

Authored by felipealmeida on Feb 19 2020, 12:15 PM.



As stated in T7744, currently there's no way to register events when
inheriting Eo interfaces for C# programmers since the registration methods are
not visible for them (as these methods are internal and used internally with
Eolian generators).

This patch solves that by generating default event implementations in Eo
interfaces. Since interface default method implementation is a C# 8.0
feature, it is not available for Mono (because of MCS compiler).


  • The following .eo:
struct Efl.Model_Changed_Event {
     ... <fields>

interface Efl.Ui.View
   ... <things not related to this patch>

   events {
      model,changed: Efl.Model_Changed_Event; [[Event dispatched when a new model is set.]]
  • Will generate the following .cs (considering unrelated removed noises):
... <annotations>
public interface IView :
    Efl.Eo.IWrapper, IDisposable
#if __MonoCS
    /// ... <docs>
    public event EventHandler<Efl.Ui.ViewModelChangedEventArgs> ModelChangedEvent;

    /// ... <docs>
    public event EventHandler<Efl.Ui.ViewModelChangedEventArgs> ModelChangedEvent
            Efl.EventCb callerCb = ((Efl.Eo.EoWrapper)this).GetInternalEventCallback(value, info => new Efl.Ui.ViewModelChangedEventArgs{ Arg =  info });
            string key = "_EFL_UI_VIEW_EVENT_MODEL_CHANGED";
            ((Efl.Eo.EoWrapper)this).AddNativeEventHandler("efl", key, callerCb, value);

            string key = "_EFL_UI_VIEW_EVENT_MODEL_CHANGED";
            ((Efl.Eo.EoWrapper)this).RemoveNativeEventHandler("efl", key, value);

    /// ... <docs>
    protected virtual void OnModelChangedEvent(Efl.Ui.ViewModelChangedEventArgs e)
        Contract.Requires(e != null, nameof(e));
        IntPtr info = Marshal.AllocHGlobal(Marshal.SizeOf(e.Arg));
        ((Efl.Eo.EoWrapper)this).CallNativeEventCallback("efl", "_EFL_UI_VIEW_EVENT_MODEL_CHANGED", info, (p) => Marshal.FreeHGlobal(p));


    ... <everything else from the interface>

Resolves T7744.

Test Plan

Run meson test in dotnet build directory.

Diff Detail

rEFL core/efl
Lint OK
No Unit Test Coverage
Build Status
Buildable 16389
jptiz created this revision.Feb 19 2020, 12:15 PM
jptiz requested review of this revision.Feb 19 2020, 12:15 PM
jptiz planned changes to this revision.Feb 19 2020, 12:18 PM
jptiz edited the summary of this revision. (Show Details)
jptiz edited projects, added efl: api; removed efl.
jptiz edited the summary of this revision. (Show Details)

Add tests.

jptiz updated this revision to Diff 29151.Feb 20 2020, 10:08 AM

Add a test-case.

jptiz added a project: Restricted Project.Feb 21 2020, 8:11 AM
felipealmeida commandeered this revision.Mar 23 2020, 10:50 AM
felipealmeida edited reviewers, added: jptiz; removed: felipealmeida.
felipealmeida edited the summary of this revision. (Show Details)

Mono removed __MonoCS macro in version 5.0