Skip to content

mrousavy/Morph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Morph

A fast .NET Standard Class Library for parsing results from an SQL query to .NET objects

Morph on NuGet Morph build status

Buy Me a Coffee at ko-fi.com

Why?

The default hardcode-index-way of creating objects from a Data Reader can be really messy for large objects with many columns.

Morph aims to simplify this process by only needing a single line of code to parse Data Reader results, and by making code bases easily extensible with the ColumnName Attributes.

A small example:

if (await reader.ReadAsync()) {
  var person = new Person() {
    FirstName = reader["PERSON_FIRST_NAME"],
    LastName = reader["PERSON_LAST_NAME"],
    Address = reader["PERSON_ADDRESS"]
  };
}

With Morph's extension Method:

var person = await reader.Parse<Person>();

(Requires a using directive to the mrousavy.Morph namespace)

Keep in mind to mark the Members you want to parse with the ColumnName Attribute in Person:

public class Person {
  [ColumnName("PERSON_FIRST_NAME")]
  public string FirstName { get; set; }   // Will be set to "PERSON_FIRST_NAME" (ColumnName parameter) from the DataBase

  [ColumnName]
  public string LastName { get; set; }    // Will be set to "LastName" (Member name) from the Database

  public string Address { get; set; }     // Will be ignored and not initialized by the Parser
}

Build

Build with .NET Core 2.0 or higher

About

🛠 A fast .NET Standard Class Library for parsing results from an SQL query to .NET objects to eliminate risky column-index hardcoding

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages