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
- Host: GitHub
- URL: https://github.com/mrousavy/morph
- Owner: mrousavy
- License: mit
- Created: 2017-08-21T17:21:43.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-06-18T08:40:45.000Z (over 5 years ago)
- Last Synced: 2025-02-15T11:16:50.666Z (11 months ago)
- Topics: csharp, dotnet, library, parser, sql
- Language: C#
- Homepage:
- Size: 26.4 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Morph
A fast .NET Standard Class Library for parsing results from an SQL query to .NET objects
## 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