#if EFL_BETA using System; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Reflection; using System.Linq; using System.ComponentModel; namespace Efl { /// Represents a bindable property as used by instances. /// /// It is internally instantiated and returned by generated extension methods. /// public class BindableProperty { /// Creates a new bindable property with the source name name. public BindableProperty(string name, Efl.Ui.IPropertyBind binder) { this.propertyName = name; this.partName = null; this.binder = binder; } /// Creates a new bindable property for part part. public BindableProperty(string partName, string partProperty, Efl.Ui.IPropertyBind binder) { this.partName = partName; this.propertyName = partProperty; this.binder = binder; } /// Binds the model property modelProperty to the property name set in the constructor. public Eina.Error Bind(string modelProperty) { if (this.partName == null) { return this.binder.BindProperty(this.propertyName, modelProperty); } else { var partHolder = this.binder as Efl.IPart; if (partHolder == null) { throw new InvalidOperationException($"Failed to cast binder {binder} to IPart"); } // We rely on reflection as GetPart is protected and not generated in IPart. var partMethod = partHolder.GetType().GetMethod("GetPart", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (partMethod == null) { throw new InvalidOperationException($"Failed to get 'GetPart' method on property binder"); } var partBinder = partMethod.Invoke(partHolder, new System.Object[] { this.partName }) as Efl.Ui.IPropertyBind; if (partBinder != null) { return partBinder.BindProperty(this.propertyName, modelProperty); } else { throw new InvalidOperationException($"Failed to get part {this.partName}"); } } } string propertyName; string partName; Efl.Ui.IPropertyBind binder; } /// Represents bindable parts as used by instances. /// /// It is internally instantiated and returned by generated extension methods. /// public class BindablePart { /// Creates a new bindable property with the binder binder. public BindablePart(string partName, Efl.Ui.IPropertyBind binder) { this.PartName = partName; this.Binder = binder; } /// The name of the part this instance wraps. public string PartName { get; private set; } /// The binder that will be used to bind the properties. public Efl.Ui.IPropertyBind Binder { get; private set; } } /// Represents bindable factory parts as used by instances. /// public class BindableFactoryPart { /// Creates a new bindable factory part with the binder binder. public BindableFactoryPart(string partName, Efl.Ui.IFactoryBind binder) { this.PartName = partName; this.Binder = binder; } /// The name of the part this instance wraps. public string PartName { get; private set; } /// The binder that will be used to bind the properties. public Efl.Ui.IFactoryBind Binder { get; private set; } /// Binds the given factory to this part. public Eina.Error BindFactory(Efl.Ui.IFactory factory) { return this.Binder.BindFactory(this.PartName, factory); } } namespace Csharp { /// Helper class to differentiate between factory extension methods. /// /// For internal use only. public class ExtensionTag where TInherited : TBase { } } } #endif