private bool RaiseRecordFieldLoadError(object target, long index, string propName, ref object value, Exception ex) { bool retValue = false; object state = value; if (Reader != null && Reader.HasRecordFieldLoadErrorSubscribed) { retValue = ChoFuncEx.RunWithIgnoreError(() => Reader.RaiseRecordFieldLoadError(target, index, propName, ref state, ex), false); if (retValue) { value = state; } } else if (target is IChoNotifyRecordFieldRead) { retValue = ChoFuncEx.RunWithIgnoreError(() => ((IChoNotifyRecordFieldRead)target).RecordFieldLoadError(target, index, propName, ref state, ex), false); if (retValue) { value = state; } } else if (_callbackRecordFieldRead != null) { retValue = ChoFuncEx.RunWithIgnoreError(() => _callbackRecordFieldRead.RecordFieldLoadError(target, index, propName, ref state, ex), false); if (retValue) { value = state; } } return(retValue); }
public static void ConvertNSetValue(this object target, PropertyDescriptor pd, object fv, CultureInfo culture, long index = 0) { PropertyInfo pi = pd.ComponentType.GetProperty(pd.Name); IChoNotifyRecordFieldRead callbackRecord = target as IChoNotifyRecordFieldRead; if (callbackRecord != null) { object state = fv; bool retValue = ChoFuncEx.RunWithIgnoreError(() => callbackRecord.BeforeRecordFieldLoad(target, index, pd.Name, ref state), true); if (retValue) { fv = state; } } try { var tpi = GetTypePropertyInfo(pd.ComponentType, pi); object[] propConverters = tpi.PropConverters; object[] propConverterParams = tpi.PropConverterParams; if (propConverters.IsNullOrEmpty()) { fv = ChoConvert.ConvertFrom(fv, pi.PropertyType, null, propConverters, propConverterParams, culture); } else { fv = ChoConvert.ConvertFrom(fv, pi.PropertyType, null, propConverters, propConverterParams, culture); } pd.SetValue(target, fv); if (callbackRecord != null) { ChoFuncEx.RunWithIgnoreError(() => callbackRecord.AfterRecordFieldLoad(target, index, pd.Name, fv), true); } } catch (Exception ex) { if (callbackRecord != null) { bool ret = ChoFuncEx.RunWithIgnoreError(() => callbackRecord.RecordFieldLoadError(target, index, pd.Name, ref fv, ex), false); if (!ret) { if (ex is ValidationException) { throw; } throw new ChoReaderException($"Failed to parse '{fv}' value for '{pd.Name}' field in '{target.GetType().Name}' object.", ex); } else { pd.SetValue(target, fv); } } } }
private bool RaiseRecordFieldLoadError(object target, long index, string propName, object value, Exception ex) { if (_callbackFieldRecord != null) { return(ChoFuncEx.RunWithIgnoreError(() => _callbackFieldRecord.RecordFieldLoadError(target, index, propName, value, ex), false)); } else if (target is IChoNotifyRecordFieldRead) { return(ChoFuncEx.RunWithIgnoreError(() => ((IChoNotifyRecordFieldRead)target).RecordFieldLoadError(target, index, propName, value, ex), false)); } else if (Reader != null) { return(ChoFuncEx.RunWithIgnoreError(() => Reader.RaiseRecordFieldLoadError(target, index, propName, value, ex), false)); } return(true); }