ekonbenefits / impromptu-interface

Static interface to dynamic implementation (duck casting). Uses the DLR combined with Reflect.Emit.
Apache License 2.0
656 stars 67 forks source link

Portable Library #2

Closed jbtule closed 7 years ago

jbtule commented 11 years ago

To make a portable library is going to going to be challenging.

First i'm splitting out the features that are easy to make portable. Such as the fun DLR api code and the FSharp code:

Dynamitey and FSharp.Dynamic

Then it's all about splitting out the emit code to platform specific dependencies, and having an easy way for Win8 to pregenerate their proxies (maybe just sample done with scriptcs?).

Then I nead to find a place for a new ImpromptuInterface.MVVM rewrite it to work on all the above portable stuff. (if possible ICustomTypeProvider is missing from PCL)

delfuria commented 9 years ago

Hi, have you any news about the PCL support for this library ? Thanks

graemechristie commented 8 years ago

Any progress on this ?. We love this library for our server side code and are working on Xamarin IOS (may not ever be possible due to reflection.emit) and Android projects with PCL libraries. We are effectively just using the ActLike<> functionality .. would this be possible to implement ourselves using the PCL Dynamitey bits ?

jbtule commented 8 years ago

Does dynamity work on Xamarin IOS? I remember talk awhile back of adding DLR support to xamarin IOS, but wasn't sure if it ever happened. I'd be interested in knowing that.

There are two parts that make up ImpromptuInterface, reflect emit and dlr. Reflect emit creates the proxies that implement the interfaces at runtime, and they could just be code generated instead at compile time, these proxies are essentially the equivalent of:

[ActLikeProxy(new Type[] {typeof (ICollection)}, typeof (object))]
[Serializable]
public class ActLike_ICollection_be4551d52cd942189281c8bce1b266ca : ActLikeProxy, ICollection
{

  public int Count
  {
    get
    {
         return (int)((IActLikeProxy)this).Original.Count
    }
  }

  public object SyncRoot
  {
    get
    {
            return (object)((IActLikeProxy)this).Original.SyncRoot
    }
  }

  public bool IsSynchronized
  {
    get
    {
         return (object)((IActLikeProxy)this).Original.IsSynchronized
    }
  }

  public void CopyTo(Array array, int index)
  {
           ((IActLikeProxy)this).Original.CopyTo(array,index)
  }

  public IEnumerator GetEnumerator()
  {
       var result = ((IActLikeProxy)this).GetEnumerator();
       var interface = result as IEnumerator;
       if(interface == null && result != null){
             return result.ActLike<IEnumerator>();
       }
       return interfaceObject;
  }
}

With this.Original being of type dynamic. If the dynamic keyword doesn't work in the runtime, even making the current design PCL isn't likely to work.

I haven't looked at PCL in awhile. At the time I used silverlight, but obviously with silverlight dead I haven't had any use myself for impromptu to be pcl. So it's not a priority for me to make pcl, but I'm sure when .net Core stabilizes that will change.

graemechristie commented 8 years ago

IOS does not support reflection.emit. There was some experimental support for the dynamic keyword announced a while ago http://stackoverflow.com/questions/15704385/can-execute-code-dynamically-in-monotouch. I'll have a look and see how well it works.

If I can grok your sample above, I might look at using something like fody for compile time code generation and the experimental dynamic support to get something working on Xamarin.iOS.

jbtule commented 7 years ago

theres a beta of ImpromptuInterface on nuget that supports .net std 2.0, it passes all the test on .net framework and .net core. I'm sure it it will not work on iOS.