/
aprogrammer
/
yessql
Обзор
Документация
Войти
/
aprogrammer
/
yessql
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/YesSql.Core/Serialization/PropertyInfoAccessor.cs
44 строки
1 KB
Sébastien Ros
Reimplement batching (#316)
31 дек 2020, 03:01
Не верифицирован
31 дек 2020, 03:01
9a8f24f
Код
Авторство
О чём код?
using System; using System.Reflection; namespace YesSql.Serialization { public class PropertyInfoAccessor { private readonly IInvoker _invoker; public PropertyInfoAccessor(PropertyInfo propertyInfo) { var delegateType = typeof(Func<,>).MakeGenericType(propertyInfo.DeclaringType, propertyInfo.PropertyType); var d = propertyInfo.GetGetMethod().CreateDelegate(delegateType); var invokerType = typeof(Invoker<,>).MakeGenericType(propertyInfo.DeclaringType, propertyInfo.PropertyType); _invoker = Activator.CreateInstance(invokerType, new object[] { d }) as IInvoker; } public object Get(object obj) { return _invoker.Invoke(obj); } private interface IInvoker { object Invoke(object target); } private sealed class Invoker<T, TResult> : IInvoker { private readonly Func<T, TResult> _d; public Invoker(Delegate d) { _d = (Func<T, TResult>)d; } public object Invoke(object target) { return _d((T)target); } } } }