fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class AnimationTrack<T> where T : struct {
  5. public void Start() { Console.WriteLine("start:" + typeof(T)); }
  6. }
  7. interface IAnimationTrack {
  8. void Start();
  9. }
  10. class AnimationTrackAdapter<T> : IAnimationTrack where T : struct {
  11. public AnimationTrack<T> Track;
  12. public AnimationTrackAdapter(AnimationTrack<T> t) { Track = t; }
  13. public void Start() { Track.Start(); }
  14. }
  15. class AnimationClip {
  16. List<IAnimationTrack> tracks = new List<IAnimationTrack>();
  17. public void Add(IAnimationTrack t) { tracks.Add(t); }
  18. public void Start() { foreach (IAnimationTrack t in tracks) { t.Start(); } }
  19. }
  20. class Program {
  21. public static AnimationTrackAdapter<T> Wrap<T>(AnimationTrack<T> t) where T : struct {
  22. return new AnimationTrackAdapter<T>(t);
  23. }
  24. static void Main(string[] args) {
  25. AnimationClip c = new AnimationClip();
  26. c.Add(Wrap(new AnimationTrack<int>()));
  27. c.Add(Wrap(new AnimationTrack<float>()));
  28. c.Start();
  29. }
  30. }
Success #stdin #stdout 0.03s 37944KB
stdin
Standard input is empty
stdout
start:System.Int32
start:System.Single