Created
March 26, 2020 17:28
-
-
Save PascalSenn/6a696e0b22730a784adaffe4634b487d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] | |
public abstract class DataLoaderAttribute : ObjectFieldDescriptorAttribute | |
{ | |
public static MethodInfo ConfigureMethod = typeof(DataLoaderAttribute) | |
.GetMethod(nameof(DataLoaderAttribute.Configure)); | |
public DataLoaderAttribute(Type dataloaderType) | |
{ | |
DataloaderType = dataloaderType; | |
} | |
public Type DataloaderType { get; } | |
public override void OnConfigure( | |
IDescriptorContext context, | |
IObjectFieldDescriptor descriptor, | |
MemberInfo member) | |
{ | |
var args = DataloaderType.GetInterface("IDataLoader")?.GetGenericArguments() | |
?? throw new InvalidOperationException(); | |
ConfigureMethod.MakeGenericMethod(DataloaderType, args[1], args[0]) | |
.Invoke(this, new object[] { context, descriptor, member }); | |
} | |
public void Configure<TLoader, TPerson, TKey>( | |
IDescriptorContext context, | |
IObjectFieldDescriptor descriptor, | |
MemberInfo member) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment