An open API service indexing awesome lists of open source software.

https://github.com/mrousavy/morph

🛠 A fast .NET Standard Class Library for parsing results from an SQL query to .NET objects to eliminate risky column-index hardcoding
https://github.com/mrousavy/morph

csharp dotnet library parser sql

Last synced: 9 months ago
JSON representation

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

Awesome Lists containing this project

README

          



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:
```cs
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:
```cs
var person = await reader.Parse();
```
_(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`:
```cs
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](https://www.microsoft.com/net/download/core) 2.0 or higher