NilResultBehavior.cs 715 B

1234567891011121314151617181920212223
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace ClaySharp.Behaviors {
  5. public class NilResultBehavior : ClayBehavior {
  6. public override object GetMember(Func<object> proceed, object self, string name) {
  7. return proceed() ?? Nil.Instance;
  8. }
  9. public override object GetIndex(Func<object> proceed, object self, IEnumerable<object> keys) {
  10. return proceed() ?? Nil.Instance;
  11. }
  12. public override object InvokeMember(Func<object> proceed, object self, string name, INamedEnumerable<object> args) {
  13. if (args.Any())
  14. return proceed();
  15. return proceed() ?? Nil.Instance;
  16. }
  17. }
  18. }