Skip to content

Commit

Permalink
ChoTypeConverter not firing #286
Browse files Browse the repository at this point in the history
  • Loading branch information
Cinchoo committed Apr 14, 2023
1 parent 72208c0 commit 8f8d663
Show file tree
Hide file tree
Showing 20 changed files with 816 additions and 40 deletions.
3 changes: 2 additions & 1 deletion src/ChoETL.Avro/ChoAvroRecordConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ private void DiscoverRecordFields(Type recordType)
foreach (PropertyDescriptor pd in ChoTypeDescriptor.GetProperties(recordType))
{
pt = pd.PropertyType.GetUnderlyingType();
if (!pt.IsSimple() && !typeof(IEnumerable).IsAssignableFrom(pt))
if (!pt.IsSimple() && !typeof(IEnumerable).IsAssignableFrom(pt)
&& !ChoTypeDescriptor.HasTypeConverters(pd.GetPropertyInfo()))
DiscoverRecordFields(pt, ref position, declaringMember == null ? pd.Name : "{0}.{1}".FormatString(declaringMember, pd.Name), optIn, null, recordFieldConfigurations);
else if (pd.Attributes.OfType<ChoAvroRecordFieldAttribute>().Any())
{
Expand Down
2 changes: 1 addition & 1 deletion src/ChoETL.JSON.NETStandard/ChoETL.JSON.NETStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<Authors>Cinchoo</Authors>
<Company>Cinchoo Inc.</Company>
<Product>ChoETL.JSON.NETStandard</Product>
<Version>1.2.1.52</Version>
<Version>1.2.1.53</Version>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>ChoETL.JSON.NETStandard.snk</AssemblyOriginatorKeyFile>
<PackageIcon>cinchoo.png</PackageIcon>
Expand Down
4 changes: 2 additions & 2 deletions src/ChoETL.JSON/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.1.52")]
[assembly: AssemblyFileVersion("1.2.1.52")]
[assembly: AssemblyVersion("1.2.1.53")]
[assembly: AssemblyFileVersion("1.2.1.53")]
//[assembly: ChoAssemblyBetaVersion("beta3")]
2 changes: 1 addition & 1 deletion src/ChoETL.NETStandard/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
using ChoETL;

[assembly: ChoAssemblyBetaVersion("beta1")]
//[assembly: ChoAssemblyBetaVersion("beta1")]
4 changes: 2 additions & 2 deletions src/ChoETL.NETStandard/ChoETL.NETStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageTags>ETL c# .NET CSV Xml JSON Flat</PackageTags>
<PackageReleaseNotes>.NET Standard version</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>1.2.1.55</Version>
<Version>1.2.1.58</Version>
<AssemblyName>ChoETL.Core</AssemblyName>
<RootNamespace>ChoETL</RootNamespace>
<SignAssembly>true</SignAssembly>
Expand All @@ -38,7 +38,7 @@
<PackageReference Include="System.CodeDom" Version="4.4.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.4.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.3" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/ChoETL/Common/ChoType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ public static object GetDefaultValue(this Type type)
? typeDefaults.GetOrAdd(type, Activator.CreateInstance)
: null;
}
public static PropertyInfo GetPropertyInfo(this PropertyDescriptor pd)
{
var classType = pd.ComponentType;
return classType.GetProperties().FirstOrDefault(p => p.Name == pd.Name);
}

public static string GetDisplayName(this PropertyDescriptor pd, string defaultValue = null)
{
if (pd != null)
Expand Down
7 changes: 7 additions & 0 deletions src/ChoETL/Common/ChoTypeDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,14 @@ public static object GetTypeConverter(MemberInfo memberInfo)
return typeConverters[0];
}

public static bool HasTypeConverters(MemberInfo memberInfo)
{
var conv = GetTypeConverters(memberInfo);
if (conv == null)
return false;

return conv.Length > 0;
}
public static object[] GetTypeConverters(MemberInfo memberInfo)
{
if (memberInfo == null)
Expand Down
3 changes: 2 additions & 1 deletion src/ChoETL/File/CSV/ChoCSVRecordConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ private void DiscoverRecordFields(Type recordType)
foreach (PropertyDescriptor pd in ChoTypeDescriptor.GetProperties(recordType))
{
pt = pd.PropertyType.GetUnderlyingType();
if (!pt.IsSimple() && !typeof(IEnumerable).IsAssignableFrom(pt))
if (!pt.IsSimple() && !typeof(IEnumerable).IsAssignableFrom(pt)
&& !ChoTypeDescriptor.HasTypeConverters(pd.GetPropertyInfo()))
DiscoverRecordFields(pt, ref position, declaringMember == null ? pd.Name : "{0}.{1}".FormatString(declaringMember, pd.Name), optIn, null, recordFieldConfigurations);
else if (pd.Attributes.OfType<ChoCSVRecordFieldAttribute>().Any())
{
Expand Down
6 changes: 3 additions & 3 deletions src/ChoETL/File/CSV/ChoCSVRecordReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private IEnumerable<object> AsEnumerable(object source, TraceSwitch traceSwitch,
Configuration.Validate(GetHeaders(header));
var dict = recFieldTypes = Configuration.CSVRecordFieldConfigurations.ToDictionary(i => i.FieldName, i => i.FieldType == null ? null : i.FieldType);
//if (Configuration.MaxScanRows == 0)
RaiseMembersDiscovered(dict);
RaiseMembersDiscovered(Configuration.CSVRecordFieldConfigurations.ToDictionary(i => i.Name, i => i.FieldType == null ? null : i.FieldType));
Configuration.UpdateFieldTypesIfAny(dict);
_configCheckDone = true;
}
Expand All @@ -374,7 +374,7 @@ private IEnumerable<object> AsEnumerable(object source, TraceSwitch traceSwitch,
Configuration.Validate(GetHeaders(pairElement.Item2));
var dict = recFieldTypes = Configuration.CSVRecordFieldConfigurations.ToDictionary(i => i.FieldName, i => i.FieldType == null ? null : i.FieldType);
//if (Configuration.MaxScanRows == 0)
RaiseMembersDiscovered(dict);
RaiseMembersDiscovered(Configuration.CSVRecordFieldConfigurations.ToDictionary(i => i.Name, i => i.FieldType == null ? null : i.FieldType));
Configuration.UpdateFieldTypesIfAny(dict);
_configCheckDone = true;
}
Expand Down Expand Up @@ -406,7 +406,7 @@ private IEnumerable<object> AsEnumerable(object source, TraceSwitch traceSwitch,
Configuration.Validate(GetHeaders(pairElement.Item2));
var dict = Configuration.CSVRecordFieldConfigurations.ToDictionary(i => i.FieldName, i => i.FieldType == null ? null : i.FieldType);
//if (Configuration.MaxScanRows == 0)
RaiseMembersDiscovered(dict);
RaiseMembersDiscovered(Configuration.CSVRecordFieldConfigurations.ToDictionary(i => i.Name, i => i.FieldType == null ? null : i.FieldType));
Configuration.UpdateFieldTypesIfAny(dict);
_configCheckDone = true;
LoadHeaderLine(pairElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ private void DiscoverRecordFields(Type recordType, string declaringMember, bool
foreach (PropertyDescriptor pd in ChoTypeDescriptor.GetProperties(recordType))
{
pt = pd.PropertyType.GetUnderlyingType();
if (!pt.IsSimple() && !typeof(IEnumerable).IsAssignableFrom(pt))
if (!pt.IsSimple() && !typeof(IEnumerable).IsAssignableFrom(pt)
&& !ChoTypeDescriptor.HasTypeConverters(pd.GetPropertyInfo()))
DiscoverRecordFields(pt, declaringMember == null ? pd.Name : "{0}.{1}".FormatString(declaringMember, pd.Name), optIn);
else if (pd.Attributes.OfType<ChoFixedLengthRecordFieldAttribute>().Any())
{
Expand Down
6 changes: 4 additions & 2 deletions src/ChoETL/File/KeyValue/ChoKVPRecordConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ private void DiscoverRecordFields(Type recordType, string declaringMember, bool
foreach (PropertyDescriptor pd in ChoTypeDescriptor.GetProperties(recordType))
{
pt = pd.PropertyType.GetUnderlyingType();
if (!pt.IsSimple() && !typeof(IEnumerable).IsAssignableFrom(pt))
if (!pt.IsSimple() && !typeof(IEnumerable).IsAssignableFrom(pt)
&& !ChoTypeDescriptor.HasTypeConverters(pd.GetPropertyInfo()))
DiscoverRecordFields(pt, declaringMember == null ? pd.Name : "{0}.{1}".FormatString(declaringMember, pd.Name), optIn);
else if (pd.Attributes.OfType<ChoKVPRecordFieldAttribute>().Any())
{
Expand All @@ -280,7 +281,8 @@ private void DiscoverRecordFields(Type recordType, string declaringMember, bool
foreach (PropertyDescriptor pd in ChoTypeDescriptor.GetProperties(recordType))
{
pt = pd.PropertyType.GetUnderlyingType();
if (pt != typeof(object) && !pt.IsSimple() && !typeof(IEnumerable).IsAssignableFrom(pt))
if (pt != typeof(object) && !pt.IsSimple() && !typeof(IEnumerable).IsAssignableFrom(pt)
&& !ChoTypeDescriptor.HasTypeConverters(pd.GetPropertyInfo()))
DiscoverRecordFields(pt, declaringMember == null ? pd.Name : "{0}.{1}".FormatString(declaringMember, pd.Name), optIn);
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/ChoETL/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.1.55")]
[assembly: AssemblyFileVersion("1.2.1.55")]
[assembly: AssemblyVersion("1.2.1.58")]
[assembly: AssemblyFileVersion("1.2.1.58")]
//[assembly: ChoAssemblyBetaVersion("beta1")]
2 changes: 1 addition & 1 deletion src/Test/ChoCSVReaderTest/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
Expand Down
7 changes: 3 additions & 4 deletions src/Test/ChoCSVReaderTest/ChoCSVReaderTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ChoCSVReaderTest</RootNamespace>
<AssemblyName>ChoCSVReaderTest</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
Expand Down Expand Up @@ -60,6 +60,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Test\BaseTests.cs" />
<None Include="020180412_045106Cropped.csv" />
<None Include="Empty.csv" />
<None Include="InterfaceTest.csv" />
Expand Down Expand Up @@ -123,9 +124,7 @@
<Name>UnitTestHelper</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Tests\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>@COPY $(ProjectDir)*.csv $(TargetDir)</PostBuildEvent>
Expand Down
3 changes: 2 additions & 1 deletion src/Test/ChoCSVReaderTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using RangeAttribute = System.ComponentModel.DataAnnotations.RangeAttribute;
using UnitTestHelper;
using System.Runtime.Serialization;
using ChoCSVReaderTest.Test;
#if !NETSTANDARD2_0
using System.Windows.Data;
#endif
Expand Down Expand Up @@ -5708,7 +5709,7 @@ public class CapVehicleCodeDesc
static void Main(string[] args)
{
ChoETLFrxBootstrap.TraceLevel = TraceLevel.Off;
Issue259();
BaseTests.TypeConverterTest();
return;

ReadMixedCSVRecords();
Expand Down
Loading

0 comments on commit 8f8d663

Please sign in to comment.