Compatibility warning for Ahead-of-Time (AOT) environments
masterBecause fast-member emits IL code during runtime, it is not compatible with constrained Ahead-of-Time (AOT) environments.
Unsupported environments include:
- Xamarin iOS
- Unity IL2CPP
repository·master·Indexed 22 days ago
https://github.com/mgravell/fast-memberA .NET library providing high-performance access to fields and properties to bypass standard reflection overhead. It includes TypeAccessor and ObjectAccessor for runtime member access, and ObjectReader for converting IEnumerable<T> sequences to DataTable or streaming data via SqlBulkCopy. Note: Not compatible with AOT environments such as Xamarin iOS and Unity IL2CPP due to runtime IL emission.
Because fast-member emits IL code during runtime, it is not compatible with constrained Ahead-of-Time (AOT) environments.
Unsupported environments include:
You can easily load a DataTable from an IEnumerable<T> by using ObjectReader.Create(data). The ObjectReader implements IDataReader, making it compatible with standard ADO.NET methods like DataTable.Load().
IEnumerable<SomeType> data = ...
var table = new DataTable();
using(var reader = ObjectReader.Create(data))
{
table.Load(reader);
}To stream data from a collection of objects directly into a database using SqlBulkCopy, use ObjectReader.Create and specify the exact member names you wish to include in the reader. This provides a very fast path for data ingestion.
using(var bcp = new SqlBulkCopy(connection))
using(var reader = ObjectReader.Create(data, "Id", "Name", "Description"))
{
bcp.DestinationTableName = "SomeTable";
bcp.WriteToServer(reader);
}Use ObjectAccessor.Create(obj) to create an accessor for a specific object instance. This is useful when the object might be static or a DLR type. You can then access its members using the indexer with the property name.
// obj could be static or DLR
var wrapped = ObjectAccessor.Create(obj);
string propName = // something known only at runtime
Console.WriteLine(wrapped[propName]);Use TypeAccessor.Create(type) to create an accessor for a specific type when member names are only known at runtime. This allows for high-performance reading and writing of fields or properties using an indexer with the object instance and the member name.
Note: This is particularly useful for accessing members of DLR types where standard reflection is difficult.
var accessor = TypeAccessor.Create(type);
string propName = // something known only at runtime
while( /* some loop of data */ )
{
accessor[obj, propName] = rowValue;
}