pmacn / Krav

A simple guard clause library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better solution for lambda argument name

pmacn opened this issue · comments

The test WhenStatementWithSingleArgument_ParamNameIsEmptyString exposes a weakness in the current implementation. It's by no means a terrible bug but it's there and it should probably go away.

The problem here is that all we have access too is simple reflection on the class generated by the compiler to handle the lambda closure. This gives us no information as to what the method in the lambda actually does.

Options

  • Find a way to get the IL or some other representation of the method that can be parsed.
  • Use the much slower approach of passing an Expression<Func<T>> that requires compiling the method every time even when the requirement is met.
  • Make a separate package for RequireThat.Lambda using platform specific implementations. Using either the hack version or Expression<Func<T>> on the platforms that do not support GetMethodBody()

However, as long as the library is used as intended this should never show it's face and maybe it should just be documented as a known flaw and we move on.