Skip to content

Instantly share code, notes, and snippets.

@GrabYourPitchforks
Last active October 1, 2017 00:59
Show Gist options
  • Save GrabYourPitchforks/bdee534a69c4fe8acea9c1d1a9e818ac to your computer and use it in GitHub Desktop.
Save GrabYourPitchforks/bdee534a69c4fe8acea9c1d1a9e818ac to your computer and use it in GitHub Desktop.
ReflectionServices proposal
using System;
using System.Security;
namespace System.Reflection
{
public delegate ref TField FieldAccessor<TField>(object target);
public delegate ref TField FieldAccessor<TTarget, TField>(ref TTarget target);
/// <summary>
/// Provides factories that can be used by serializers, formatters, and DI systems
/// to perform reflection-like activities in performance-critical code paths.
/// </summary>
[SecurityCritical]
public static class ReflectionServices
{
/*
* FIELD ACCESSORS, GETTERS, AND SETTERS
* TODO: This depends on exposing field offsets from CLR
* in order to avoid codegen.
*/
public static FieldAccessor<TField> CreateFieldAccessor<TField>(FieldInfo fieldInfo)
{
throw new NotImplementedException();
}
public static FieldAccessor<TTarget, TField> CreateFieldAccessor<TTarget, TField>(FieldInfo fieldInfo)
{
throw new NotImplementedException();
}
public static Func<object, object> CreateFieldGetter(FieldInfo fieldInfo)
{
throw new NotImplementedException();
}
public static Func<object, TField> CreateFieldGetter<TField>(FieldInfo fieldInfo)
{
throw new NotImplementedException();
}
public static Func<TTarget, TField> CreateFieldGetter<TTarget, TField>(FieldInfo fieldInfo)
{
throw new NotImplementedException();
}
public static Action<object, object> CreateFieldSetter(FieldInfo fieldInfo)
{
throw new NotImplementedException();
}
public static Action<object, TField> CreateFieldSetter<TField>(FieldInfo fieldInfo)
{
throw new NotImplementedException();
}
public static Action<TTarget, TField> CreateFieldSetter<TTarget, TField>(FieldInfo fieldInfo)
{
// Should throw if 'TTarget' is a value type.
throw new NotImplementedException();
}
/*
* PARAMETERLESS OBJECT CREATION
* TODO: This depends on FormatterServices.GetUninitializedObjectFactory
* in order to avoid codegen.
*/
public static Func<object> CreateInstanceFactory(Type type)
{
throw new NotImplementedException();
}
public static Func<T> CreateInstanceFactory<T>()
{
throw new NotImplementedException();
}
/*
* PARAMETERFUL OBJECT CREATION
* TODO: This requires special new delegate invocation functionality
* within the CLR in order to avoid codegen.
*/
public static Func<object[], object> CreateInstanceFactory(ConstructorInfo constructorInfo)
{
throw new NotImplementedException();
}
public static Func<object[], T> CreateInstanceFactory<T>(ConstructorInfo constructorInfo)
{
throw new NotImplementedException();
}
public static TDelegate CreateInstanceFactoryTyped<TDelegate>(ConstructorInfo constructorInfo)
/* where TDelegate : Delegate */
{
throw new NotImplementedException();
}
/*
* PROPERTY GETTERS AND SETTERS
* TODO: Support non-indexed properties? Probably not a hard requirement
* since it's an advanced case and callers can use regular method binding
* to pull it off.
*/
public static Func<object, object> CreatePropertyGetter(PropertyInfo propertyInfo)
{
throw new NotImplementedException();
}
public static Func<object, TProperty> CreatePropertyGetter<TProperty>(PropertyInfo propertyInfo)
{
throw new NotImplementedException();
}
public static Func<TTarget, TProperty> CreatePropertyGetter<TTarget, TProperty>(PropertyInfo propertyInfo)
{
throw new NotImplementedException();
}
public static Action<object, object> CreatePropertySetter(PropertyInfo propertyInfo)
{
throw new NotImplementedException();
}
public static Action<object, TProperty> CreatePropertySetter<TProperty>(PropertyInfo propertyInfo)
{
throw new NotImplementedException();
}
public static Action<TTarget, TProperty> CreatePropertySetter<TTarget, TProperty>(PropertyInfo propertyInfo)
{
// Should throw if 'TTarget' is a value type.
throw new NotImplementedException();
}
}
}
@IDisposable
Copy link

Needz implementationz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment