Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从泛型类型派生的类上的PostSharp方面生成错误_C#_Generics_Postsharp - Fatal编程技术网

C# 从泛型类型派生的类上的PostSharp方面生成错误

C# 从泛型类型派生的类上的PostSharp方面生成错误,c#,generics,postsharp,C#,Generics,Postsharp,我试图在类上使用调度方面将执行推送到UI线程,但在构建时遇到错误。以下是错误: 无法将方面添加到泛型类型实例。将特性添加到相应的泛型类型定义中 将方面放在从泛型类型派生的类上似乎有问题 下面是一个简化的代码示例,可以重现这一点: interface IView { } class Presenter<T> { } class DataPresenter : Presenter<IView> { [Dispatched] void DoSomething

我试图在类上使用调度方面将执行推送到UI线程,但在构建时遇到错误。以下是错误:

无法将方面添加到泛型类型实例。将特性添加到相应的泛型类型定义中

将方面放在从泛型类型派生的类上似乎有问题

下面是一个简化的代码示例,可以重现这一点:

interface IView
{
}

class Presenter<T>
{
}

class DataPresenter : Presenter<IView>
{
    [Dispatched]
    void DoSomething()
    {
    }
}
interface-IView
{
}
课堂演示者
{
}
类DataPresenter:Presenter
{
[已发送]
无效剂量测定法()
{
}
}

我是否遗漏了一些东西,或者无法在继承泛型类型的类上使用方面?

正如Daniel在评论中提到的,这是PostSharp中的一个bug,但我找到了解决方法。我修改了presenter类:

class Presenter<T> : DispatcherObject, IDispatcherObject
{
    IDispatcher IDispatcherObject.Dispatcher => DispatcherFactory.GetDispatcherForWindowsDispatcher(Dispatcher);
}
类演示者:DispatcherObject,IDispatcherObject
{
IDispatcher IDispatcherObject.Dispatcher=>DispatcherFactory.GetDispatcherForWindowsDispatcher(Dispatcher);
}

在我的代码中,Presenter已经从DispatcherObject继承,因此实现IDispatcherObject接口解决了我的问题。

这是[Dispatched]属性的一个错误,它试图将服务方面引入基类。修好后我们会尽快通知您。作为一种解决方法,请为
Presenter
声明非泛型基类,或将
Presenter
移动到另一个程序集。谢谢我找到了解决问题的方法,我将在下面添加我的答案。更新:相关错误已在PostSharp 4.3.24中修复。更新:相关错误已在PostSharp 4.3.24中修复。