public static Type GetDelegateType(FluentActionHandlerDefinition handler) { if (handler.Type == FluentActionHandlerType.Action && !handler.Async) { return(GetActionType(handler)); } else { return(GetFuncType(handler)); } }
public static Type GetFuncType(FluentActionHandlerDefinition handler) { var argumentTypes = handler.Usings.Select(@using => @using.Type).ToList(); var resultType = GetReturnTypeOrTaskType(handler); argumentTypes.Add(resultType); var unspecifiedGenericFuncType = GetUnspecifiedGenericFuncType(argumentTypes.Count); var specifiedGenericFuncType = unspecifiedGenericFuncType.MakeGenericType(argumentTypes.ToArray()); return(specifiedGenericFuncType); }
public static Type GetReturnTypeOrTaskType(FluentActionHandlerDefinition handler) { if (handler.Async && handler.ReturnType == null) { return(typeof(Task)); } else if (handler.Async && handler.ReturnType != null) { return(typeof(Task <>).MakeGenericType(handler.ReturnType)); } else { return(handler.ReturnType); } }
public static Type GetActionType(FluentActionHandlerDefinition handler) { var argumentTypes = handler.Usings.Select(@using => @using.Type).ToList(); if (argumentTypes.Count == 0) { return(typeof(Action)); } else { var unspecifiedGenericActionType = GetUnspecifiedGenericActionType(argumentTypes.Count); var specifiedGenericActionType = unspecifiedGenericActionType.MakeGenericType(argumentTypes.ToArray()); return(specifiedGenericActionType); } }