Skip to content

Instantly share code, notes, and snippets.

@smoogipoo
Created July 12, 2017 09:36
Show Gist options
  • Save smoogipoo/e75eecd3dfad3470223dbb4638872922 to your computer and use it in GitHub Desktop.
Save smoogipoo/e75eecd3dfad3470223dbb4638872922 to your computer and use it in GitHub Desktop.
class Transformable<T>
where T : Transformable<T>
{
}
class TransformationContinuation<T>
where T : Transformable<T>
{
T origin;
public TransformationContinuation(T origin)
{
this.origin = origin;
}
public T Then()
{
... // Delays?
return origin;
}
public TransformationContinuation<T> Then(Action action)
{
... // Do something with action
return new TransformationContinuation<T>(origin);
}
public static implicit operator T(TransformationContinuation<T> continuation) => T;
}
class Drawable : Transformable<Drawable>
{
public TransformationContinuation<Drawable> ScaleTo()
{
...
return new TransformationContinuation<Drawable>(this);
}
public TransformationContinuation<Drawable> RotateTo()
{
...
return new TransformationContinuation<Drawable>(this);
}
}
class Sprite : Drawable { }
usage:
1:
Drawable d;
d.ScaleTo().Then().RotateTo();
2:
Drawable d;
d.ScaleTo().Then().RotateTo().ScaleTo().Then().ScaleTo();
3:
Drawable d;
Sprite s;
d.ScaleTo().Then(_ => s.Alpha = 5).ScaleTo().Then().ScaleTo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment