我正在使用Visual Studio和C#8.0
编辑,跳到下面的编辑以获取更好的代码
我在这里的库中定义了一些基类:
using System.Collections.Generic;
using System.Threading;
namespace MeepTech.Jobs {
public abstract class QueueManagerJob<QueueItemType> : ThreadedJob {
protected List<QueueItemType> queue;
protected Dictionary<QueueItemType,CancellationTokenSource> cancelationSources;
protected QueueManagerJob(int maxChildJobsCount = 10);
public void deQueue(QueueItemType[] queueObjects);
public void enQueue(QueueItemType[] queueObjects);
protected abstract QueuetaskChildJob getchildJob(QueueItemType queueObject,Dictionary<QueueItemType,CancellationTokenSource> parentCancelationSources);
protected virtual bool isAValidQueueItem(QueueItemType queueItem);
protected override void jobFunction();
protected abstract class QueuetaskChildJob : ThreadedJob {
protected QueueItemType queueItem;
protected QueuetaskChildJob(QueueItemType queueItem,CancellationTokenSource> parentCancellationSources);
protected abstract void doWork(QueueItemType queueItem,CancellationToken cancellationToken);
protected override void finallyDo();
protected override void jobFunction();
}
}
}
我试图在这里扩展这些类:
/// <summary>
/// A base job for managing chunk work queues
/// </summary>
abstract class LevelQueueManagerJob : QueueManagerJob<Coordinate> {
/// <summary>
/// Base class for child jobs that manage chunk loading and unloading
/// </summary>
protected abstract class ChunkColumnLoadingJob : QueuetaskChildJob {
/// <summary>
/// The level we're loading for
/// </summary>
protected Level<BlockStorageType> level;
/// <summary>
/// Make a new job
/// </summary>
/// <param name="level"></param>
/// <param name="chunkColumnLocation"></param>
protected ChunkColumnLoadingJob(
Level<BlockStorageType> level,Coordinate chunkColumnLocation,Dictionary<Coordinate,CancellationTokenSource> parentCancellationSources
) : base(chunkColumnLocation,parentCancellationSources) {
this.level = level;
}
/// <summary>
/// Do the actual work on the given chunk for this type of job
/// </summary>
protected abstract void doWorkOnChunk(Coordinate chunkLocation);
/// <summary>
/// Do work
/// </summary>
protected override void doWork(Coordinate chunkColumnLocation,CancellationToken cancellationToken) {
Coordinate columnTop = (chunkColumnLocation.x,level.chunkBounds.y,chunkColumnLocation.z);
Coordinate columnBottom = (chunkColumnLocation.x,chunkColumnLocation.z);
columnBottom.until(columnTop,chunkLocation => {
if (!cancellationToken.IsCancellationRequested) {
doWorkOnChunk(chunkLocation);
return true;
}
return false;
});
}
}
/// <summary>
/// The level we're loading for
/// </summary>
protected Level<BlockStorageType> level;
/// <summary>
/// Create a new job,linked to the level
/// </summary>
/// <param name="level"></param>
protected LevelQueueManagerJob(Level<BlockStorageType> level) : base(MaxChunkLoadingJobsCount) {
this.level = level;
}
}
}
在将上述类转换为库之前,它按预期工作,但是,现在我收到属于ChunkColumnLoadingJob
子类的类的错误消息:
错误CS0534
'ColumnLoadedLevel<BlockStorageType>.JUnloadChunks.JUnloadChunkColumn'
未实现继承的抽象成员'QueueManagerJob<Coordinate>.QueuetaskChildJob.doWork(Coordinate,CancellationToken)'
VoxelTerrainA2 C:\ Users \ super \ Projects \ MonoGame \ VoxelTerrainA2 \ Evix \ Voxel \ Collections \ ColumnLoadedLevel.cs 281
即使它在那里。我还可以使用Visual Studio为缺少的功能自动生成覆盖功能,给我这样的条件:
protected override void doWork(Coordinate queueItem,CancellationToken cancellationToken) {
throw new NotImplementedException();
}
实际上会引发与其他函数相同的确切错误:
ColumnLoadedLevel<BlockStorageType>.LevelQueueManagerJob.ChunkColumnLoadingJob.doWork(Coordinate,CancellationToken)
:找不到适合的方法来覆盖
我不知道自己在做什么错,有人有任何想法吗?
编辑:
删除代码以更轻松地查看问题:
我的图书馆文件:
namespace MeepTech.Jobs {
public abstract class TestChildQueueJob<QueueItemType> : ThreadedJob {
protected TestChildQueueJob();
protected abstract void doWork(QueueItemType queueItem,CancellationToken cancellationToken);
}
}
CS版本:
/// <summary>
/// Child job for doing work on objects in the queue
/// </summary>
public abstract class TestChildQueueJob<QueueItemType> {
/// <summary>
/// The do work function
/// </summary>
/// <param name="queueItem"></param>
/// <param name="cancellationToken"></param>
protected abstract void doWork(QueueItemType queueItem,CancellationToken cancellationToken);
}
}
新代码:
class testjob : QueuetaskChildJob<Coordinate> {
protected override void doWork(Coordinate queueItem,CancellationToken cancellationToken) {
throw new NotImplementedException();
}
}
class testjob
引发错误:
严重性代码描述项目文件行抑制 状态抑制状态错误CS0534'testjob'未实现 继承的抽象成员
QueuetaskChildJob<Coordinate>.doWork(Coordinate,CancellationToken)
VoxelTerrainA2 C:\ Users \ super \ Projects \ MonoGame \ VoxelTerrainA2 \ Evix \ Voxel \ Collections \ testjob.cs 10有效
和testjob.doWork
出现错误:
严重性代码描述项目文件行抑制 状态抑制状态错误CS0115
testjob.doWork(Coordinate,CancellationToken)
:找不到适合的方法来覆盖VoxelTerrainA2 C:\ Users \ super \ Projects \ MonoGame \ VoxelTerrainA2 \ Evix \ Voxel \ Collections \ testjob.cs 11有效
请注意,这确实有效:
namespace MeepTech.Jobs {
/// <summary>
/// Child job for doing work on objects in the queue
/// </summary>
public abstract class TestChildQueueJob<QueueItemType> {
/// <summary>
/// The do work function
/// </summary>
/// <param name="queueItem"></param>
/// <param name="cancellationToken"></param>
protected abstract void doWork(QueueItemType queueItem,CancellationToken cancellationToken);
}
class testjob : TestChildQueueJob<int> {
protected override void doWork(int queueItem,CancellationToken cancellationToken) {
throw new NotImplementedException();
}
}
}
仅当通过DLL文件(即库)加载基类并且不包含.cs文件本身时,此方法才起作用。