[Feature] RespondWithModal() which accepts an IModal instance as template (#2564)
* introduce overload for responding to an interaction with an instatiated IModal obj * add inline docs to ModalInfo.PropertyInfo * Apply suggestions from code review Co-authored-by: Casmir <68127614+csmir@users.noreply.github.com> --------- Co-authored-by: Casmir <68127614+csmir@users.noreply.github.com>
This commit is contained in:
@@ -10,7 +10,6 @@ namespace Discord.Interactions
|
||||
internal static class ReflectionUtils<T>
|
||||
{
|
||||
private static readonly TypeInfo ObjectTypeInfo = typeof(object).GetTypeInfo();
|
||||
|
||||
internal static T CreateObject (TypeInfo typeInfo, InteractionService commandService, IServiceProvider services = null) =>
|
||||
CreateBuilder(typeInfo, commandService)(services);
|
||||
|
||||
@@ -166,6 +165,21 @@ namespace Discord.Interactions
|
||||
return Expression.Lambda<Action<T, object>>(assign, instanceParam, valueParam).Compile();
|
||||
}
|
||||
|
||||
internal static Func<T, object> CreateLambdaPropertyGetter(PropertyInfo propertyInfo)
|
||||
{
|
||||
var instanceParam = Expression.Parameter(typeof(T), "instance");
|
||||
var prop = Expression.Property(instanceParam, propertyInfo);
|
||||
return Expression.Lambda<Func<T, object>>(prop, instanceParam).Compile();
|
||||
}
|
||||
|
||||
internal static Func<T, object> CreateLambdaPropertyGetter(Type type, PropertyInfo propertyInfo)
|
||||
{
|
||||
var instanceParam = Expression.Parameter(typeof(T), "instance");
|
||||
var instanceAccess = Expression.Convert(instanceParam, type);
|
||||
var prop = Expression.Property(instanceAccess, propertyInfo);
|
||||
return Expression.Lambda<Func<T, object>>(prop, instanceParam).Compile();
|
||||
}
|
||||
|
||||
internal static Func<object[], object[], T> CreateLambdaMemberInit(TypeInfo typeInfo, ConstructorInfo constructor, Predicate<PropertyInfo> propertySelect = null)
|
||||
{
|
||||
propertySelect ??= x => true;
|
||||
|
||||
Reference in New Issue
Block a user