Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mgravell/fast-member
Automatically exported from code.google.com/p/fast-member
https://github.com/mgravell/fast-member
Last synced: 21 days ago
JSON representation
Automatically exported from code.google.com/p/fast-member
- Host: GitHub
- URL: https://github.com/mgravell/fast-member
- Owner: mgravell
- License: apache-2.0
- Created: 2015-11-23T20:09:54.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-03-30T22:29:29.000Z (7 months ago)
- Last Synced: 2024-10-04T08:50:07.286Z (about 1 month ago)
- Language: C#
- Size: 183 KB
- Stars: 1,018
- Watchers: 59
- Forks: 137
- Open Issues: 60
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
- Awesome-Nuget-Packages - **FastMember**
README
Fast access to .net fields/properties
=====================================In .NET reflection is slow... well, kinda slow. If you need access to the members of an arbitrary type, with the type and member-names known only at runtime - then it is frankly **hard** (especially for DLR types). This library makes such access easy and fast.
An introduction to the reasons behind fast-member can be found on my blog; example usage is simply:
```csharp
var accessor = TypeAccessor.Create(type);
string propName = // something known only at runtime
while( /* some loop of data */ )
{
accessor[obj, propName] = rowValue;
}
```
or
```csharp
// obj could be static or DLR
var wrapped = ObjectAccessor.Create(obj);
string propName = // something known only at runtime
Console.WriteLine(wrapped[propName]);
```
### Ever needed an `IDataReader`?This is pretty common if you are doing object-mapping between an object model and ADO.NET concepts such as `DataTable` or `SqlBulkCopy`; loading a `DataTable` (yes, some people still use it) from a sequence of typed objects can now be as easy as:
```csharp
IEnumerable data = ...
var table = new DataTable();
using(var reader = ObjectReader.Create(data))
{
table.Load(reader);
}
```
(the `Create` method offers parameters to control the specific members, if needed)Or if you want to throw the data into a database as fast as humanly possible:
```csharp
using(var bcp = new SqlBulkCopy(connection))
using(var reader = ObjectReader.Create(data, "Id", "Name", "Description"))
{
bcp.DestinationTableName = "SomeTable";
bcp.WriteToServer(reader);
}
```### Ahead of Time
Library emits IL code during runtime. Will not work in constrained Ahead of Time environments. Xamarin iOS and Unity IL2CPP are such.