ObjectExtensions.cs 362 B

12345678910111213141516
  1. using System;
  2. namespace Wayne.Lib
  3. {
  4. public static class ObjectExtensions
  5. {
  6. public static TGeneral WhenOfType<TGeneral, TSpecial>(this TGeneral o, Action<TSpecial> action) where TSpecial : TGeneral
  7. {
  8. if (o is TSpecial)
  9. {
  10. action((TSpecial)o);
  11. }
  12. return o;
  13. }
  14. }
  15. }