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); } } } }
public ChoParquetRecordReader(Type recordType, ChoParquetRecordConfiguration configuration) : base(recordType, false) { ChoGuard.ArgumentNotNull(configuration, "Configuration"); Configuration = configuration; _callbackRecordFieldRead = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyRecordFieldRead>(recordType); _callbackFileRead = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyFileRead>(recordType); _callbackRecordRead = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyRecordRead>(recordType); _callbackRecordSeriablizable = ChoMetadataObjectCache.CreateMetadataObject <IChoRecordFieldSerializable>(recordType); }
public ChoAvroRecordReader(Type recordType, ChoAvroRecordConfiguration configuration) : base(recordType, false) { ChoGuard.ArgumentNotNull(configuration, "Configuration"); Configuration = configuration; _callbackRecordFieldRead = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyRecordFieldRead>(recordType); _callbackFileRead = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyFileRead>(recordType); _callbackRecordRead = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyRecordRead>(recordType); _callbackRecordSeriablizable = ChoMetadataObjectCache.CreateMetadataObject <IChoRecordFieldSerializable>(recordType); System.Threading.Thread.CurrentThread.CurrentCulture = Configuration.Culture; }
public ChoKVPRecordReader(Type recordType, ChoKVPRecordConfiguration configuration) : base(recordType) { ChoGuard.ArgumentNotNull(configuration, "Configuration"); Configuration = configuration; _callbackRecordFieldRead = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyRecordFieldRead>(recordType); _callbackFileRead = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyFileRead>(recordType); _callbackRecordRead = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyRecordRead>(recordType); _customKVPRecord = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyKVPRecordRead>(recordType); //Configuration.Validate(); }
public ChoFixedLengthRecordReader(Type recordType, ChoFixedLengthRecordConfiguration configuration) : base(recordType) { ChoGuard.ArgumentNotNull(configuration, "Configuration"); Configuration = configuration; _callbackRecord = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyRecordRead>(recordType); _callbackFieldRecord = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyRecordFieldRead>(recordType); if (_callbackFieldRecord == null) { _callbackFieldRecord = _callbackRecord; } _customColumnMappableRecord = ChoMetadataObjectCache.CreateMetadataObject <IChoCustomColumnMappable>(recordType); _emptyLineReportableRecord = ChoMetadataObjectCache.CreateMetadataObject <IChoEmptyLineReportable>(recordType); //Configuration.Validate(); }
public override void Validate(object state) { base.Validate(state); if (NotifyRecordReadType != null) { NotifyFileReadObject = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyFileRead>(NotifyRecordReadType); NotifyRecordReadObject = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyRecordRead>(NotifyRecordReadType); NotifyRecordFieldReadObject = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyRecordFieldRead>(NotifyRecordReadType); } if (NotifyRecordWriteType != null) { NotifyRecordWriteObject = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyRecordWrite>(NotifyRecordWriteType); } //if (SubRecordConfigurations.Count == 0) // throw new ChoRecordConfigurationException("Atleast one record type must be registered."); foreach (Type t in SubRecordConfigurations.Keys) { if (SubRecordConfigurations[t] == null) { throw new ChoRecordConfigurationException($"Missing record configuration for '{t.Name}' type."); } } if (RecordTypeConfiguration != null) { if (RecordSelector == null && RecordTypeCodeExtractor == null) { if (RecordTypeConfiguration.StartIndex < 0) { throw new ChoRecordConfigurationException("RecordTypeConfiguration start index must be >= 0."); } else { if (RecordTypeConfiguration.Size <= 0) { throw new ChoRecordConfigurationException("RecordTypeConfiguration size must be > 0."); } } } } }