DataObjectProcessor 1.0.1

dotnet add package DataObjectProcessor --version 1.0.1                
NuGet\Install-Package DataObjectProcessor -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DataObjectProcessor" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DataObjectProcessor --version 1.0.1                
#r "nuget: DataObjectProcessor, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DataObjectProcessor as a Cake Addin
#addin nuget:?package=DataObjectProcessor&version=1.0.1

// Install DataObjectProcessor as a Cake Tool
#tool nuget:?package=DataObjectProcessor&version=1.0.1                

DataObjectProcessor

What is this package?

DataObjectProcessor is a basic data access package to make it easier to work with differing data storage techniques. Designed initially to allow the quick processing of CSV files into a List of Generic Types but contrained to an interface so that other data storage techniques can be added later.

How do I use this package?

  1. Install the package using Nuget into your project.

  2. Use the package from the namespace 'DataObjectProcessor'

/Class1.cs

using DataObjectProcessor;
  1. Add the Data Processor of your choosing.
/Class1.cs

IDataProcessor dp = new DataObjectProcessor.CsvProcessor.CsvDataProcessor(@"C:\MyCsvFile.csv");

  1. Itterate down the file by using one of the methods outlined in the interface.
/Class1.cs

await foreach (var i in dp.GetAsyncEnumerable<MyClass>()){
    Console.WriteLine(i.MyProperty);
}

class MyClass {
    public string MyProperty { get; set; }
}

Special Considerations

There are a few ways to customize the packages usage.

  1. Change the options used by the CsvProcessor
/Class1.cs

IDataProcessor dp = new CsvDataProcessor(@"C:\MyCsvFile.csv", new CsvProcessorOptions()
            {
                ColumnSeperator = ",",
                FieldsAreEnclosedInQuotes = true,
                FirstRowHasHeadings = true,
                ThrowWhenUnableToSetPropertyValue = true
            });
  1. Setup Csv Column Index's to match properties to columns with different names
class MyClass {
    [CsvIndex(1)]
    public string MyProperty { get; set; }

    [CsvIndex(2)]
    public string SecondProperty { get; set; }

    public string Another { get; set; }
}

2.1 Example CSV File (For above)

Another,Firstname,Lastname
123,"Wayne","Johnson"

In the above example, '123' would be mapped to 'Another as the column header matches the property name, "Wayne" would be mapped to "MyProperty" as it's Index in the Csv file is '1', and "Johnson" would be mapped to "SecondProperty"

Exceptions.

  1. 'PropertyConversionException' will be thrown in the data inside the Csv file is unable to be matched to the property. You can set 'ThrowWhenUnableToSetPropertyValue' to false, thus - when the data cannot be converted to the property type, it will silently fail and leave the property unpopulated.

  2. 'PropertyIndexException' will be thrown if you set the same column index on two properties. You can only have one property mapped to one column.


Tips

More underlying data storage techniques will be added in the future, as and when I personal need them. If you find any tools within here helpful, consider buying me a beer - I'd appreciate it.

Use PayPal to buy me a beer.

Change Log
1.0.0 → Initial Publish
1.0.1 → Change to make it slightly more reliable. Was missing some properties.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 432 10/11/2022
1.0.0 422 9/26/2022