无法将Task转换为TaskCollection

时间:2013-06-18 07:18:24

标签: c# collections

我的测试代码片段:
    使用(ShimsContext.Create())     {
     taskService = new ShimTaskService             {                 TargetServerGet =()=> “192.168.100.1”,                 UserNameGet =()=> “用户”,                 UserAccountDomainGet =()=> “TESTDOMAIN”                 UserPasswordGet =()=> “P / W”,                 RootFolderGet =()=>新的ShimTaskFolder                 {                    TasksGet =()=>新列表{new ShimTask {NameGet =()=>任务名称 }};                 }             }             我有错误:

        > Cannot convert lambda expression to type system.collections.generic.List< Microsoft.Win32.TaskScheduler.Task>
        > to return type system.collections.generic.List<
        > Microsoft.Win32.TaskScheduler.TaskCollection>. How convert this
        > collection?    

                // TaskGet: 
                public FakesDelegates.Func<TaskCollection> TasksGet { set; }

                // TaskCollection:
                public sealed class TaskCollection : IEnumerable<Task>, IEnumerable, IDisposable
            {
                public int Count { get; }

                public Task this[int index] { get; }
                public Task this[string name] { get; }

                public void Dispose();
                public IEnumerator<Task> GetEnumerator();
            }

1 个答案:

答案 0 :(得分:0)

假设这是TaskCollection from codeplex,那么无法创建自己的TaskCollection以包装任意Task。这不是预期的用途。您需要更改设计,或更改托管包装器的源并重建库。