我有这样的代码:
private Func<Request, Response, byte[], string, string, Task> _started;
private Func<Request, Response, byte[], string, string, Task> _progress;
private Func<Request, Response, byte[], string, string, Task> _completed;
private Func<Request, Response, byte[], string, string, Task> _errorOccurred;
private Func<Request, Response, byte[], string, string, Task> _cancelled;
我最好有类似的东西:
typedef Func<Request, Response, byte[], string, string, Task> StatusUpdateAsyncCallback; // in C++ way.
private StatusUpdateAsyncCallback _started;
// and so on.
无法弄清楚如何使用Func执行此操作。我习惯代表(我没有这个问题,因为我可以为任何委托提供一个唯一的名称),但现在无法弄清楚如何为Func声明重复这个。
我正在从像delegate Task StatusUpdateAsyncCallback(Request req, Response resp, byte[] data, string account, string alias)
之类的委托类型的简单声明中迁移,因为我现在将依赖于一些特定于Func的能力(例如,可以创建一个适用于各种类型的扩展方法Func委托具有一定数量的参数,而'经典'委托类型以这种方式不兼容)。如果需要更多信息,可以在How to write extension method which will make invocation list members in multicast C# delegate run sequentially?
答案 0 :(得分:4)
您可以使用<?php
include "dbConnect.php";
function getTimeTable($tutorID, $parseDate) {
//'$parseDate'
global $con;
$today = date ( "Y-m-d" );
$time_table_res = mysqli_query ( $con, "SELECT BeginTime, EndTime FROM TimeTable WHERE TutorId = '$tutorID'" );
$timetable = array ();
$num_rows = mysqli_num_rows ( $time_table_res );
if ($num_rows > 0) {
while ( $row = mysqli_fetch_array ( $time_table_res, MYSQLI_ASSOC ) ) {
$begin_time = DateTime::createFromFormat ( 'Y-m-d g:i a', $parseDate . " " . $row ['BeginTime'] );
$end_time = DateTime::createFromFormat ( 'Y-m-d g:i a', $parseDate . " " . $row ['EndTime'] );
while ( $begin_time <= $end_time ) {
$fdate = date_format($begin_time, 'g:i a');
array_push ( $timetable, $fdate );
$begin_time->add ( new DateInterval ( 'PT30M' ) );
}
}
}
return $timetable;
}
?>
(在每个文件中):
using
所有类型名称都应完全合格。
答案 1 :(得分:2)
您可以使用using
创建一个类型别名,虽然它只适用于该文件,而不适用于程序集的其余部分。
using StatusUpdateAsyncCallback =
System.Func<Request, Response, byte[], string, string, System.Threading.Tasks.Task>;
答案 2 :(得分:0)
至少对于相同的源文件,这将起作用:
using StatusUpdateAsyncCallback = System.Func<Request, Response, byte[], string, string, System.Threading.Tasks.Task>;
关键是始终在using指令(System.Func
,System.Threading.Tasks.Task
)中提供完整的类型名称。早期using System.Threading.Tasks
和using System
声明无效。