adamped / xamarin.flutter

Running Flutter on Xamarin
MIT License
249 stars 39 forks source link

CSharpWriter: covariant argument types #48

Closed JeroMiya closed 5 years ago

JeroMiya commented 5 years ago

For example, see the AbstractNode class in the flutter sources.

How can it cross-compile these and retain type safety (or as much as possible with C#?). I thought maybe it could rewrite the class to use a covariant generic interface.

So for AbstractNode, for example, it would generate something like this interface (not sure if this would work):

    public interface INode {}
    public interface INode<out T> : INode
    {
        INode owner { get; } // had to loosen the type here, not sure if we can do better?
        INode<INode<T>> parent { get; }
        int depth { get; set; }
        bool attached { get; }

        void attach(INode owner);
        void redepthChildren();
        void detach();
    }

    public class AbstractNode<T> : INode<T> {
        ...etc... 
        protected void dropChild<TChild>(INode<TChild> child) { ...etc.. }
    }
adamped commented 5 years ago

At the moment we just input as the type, if it doesn't define one. We might look at other approaches in the future, just trying to get a very basic working version complete first.