public static void True(bool condition, string message, IConstraintsViolations errors) { if (!condition) { errors.Add(message); } }
private static void AssertNullCheckForEveryPossibleArgumentOf(IConstraintsViolations violations, IConstructorWrapper constructor, FallbackTypeGenerator fallbackTypeGenerator) { for (int i = 0; i < constructor.GetParametersCount(); ++i) { var parameters = constructor.GenerateAnyParameterValues(Any.Instance); if (SmartType.ForTypeOf(parameters[i]).CanBeAssignedNullValue()) { parameters[i] = null; try { fallbackTypeGenerator.GenerateInstance(parameters); violations.Add("Not guarded against nulls: " + constructor + ", Not guarded parameter: " + constructor.GetDescriptionForParameter(i)); } catch (TargetInvocationException exception) { if (exception.InnerException.GetType() == typeof(ArgumentNullException)) { //do nothing, this is the expected case } else { throw; } } } } }