// Because instead of an exception, the result should return. public IEnumerable <ValidationResult> Validate(object source, IMethodAccessor method) { var validationResults = new List <ValidationResult>(); if (method == null) { return(validationResults); } try { // Gets invariant method result. var methodResult = method.Invoke(source); // Prepare validation result. methodResultDispatcher.DispatchResult(methodResult, method.InvariantName, validationResults); } catch (Exception exception) { // Prepare result from exception. methodResultDispatcher.DispatchResult(method.MethodName, exception, validationResults); } return(validationResults); }
private object FormatValue(AuditEntryState state, string name, object value) { if (value == null) { return(null); } var valueType = value.GetType(); try { object returnValue = valueType.IsEnum ? Enum.GetName(valueType, value) : value; IMethodAccessor formatMethod = Configuration.GetFormatter(state.ObjectType, name); if (formatMethod == null) { return(returnValue); } var context = new AuditPropertyContext { ValueType = valueType, Entity = state.Entity, Value = returnValue }; try { return(formatMethod.Invoke(null, new[] { context })); } catch { // eat format error? return(returnValue); } } catch (Exception ex) { Trace.TraceError(ex.Message); return(_errorText); } }