0
プリズムPubSubのスタイルのイベントの使用:ただし、直接変換私は次のようにC#での有効な構文は次のようになりますことを知って、C++/CLIでイベントアグリゲータを作成しようとしているC++/CLI
//C# code
public partial class Foo : UserControl, IView, IDisposable
{
private IEventAggregator _aggregator;
public Foo(IEventAggregator aggregator)
{
InitializeComponent();
this._aggregator = aggregator;
if (this._aggregator == null)
throw new Exception("null pointer");
_subToken =_aggregator.GetEvent<fooEvent>().Subscribe(Handler, ThreadOption.UIThread, false);
}
private SubscriptionToken _subToken = null;
private void Handler(fooEventPayload args)
{
//this gets run on the event
}
}
これをC++/CLIに渡すと、指定された行の "管理されたクラスに対してメンバへのポインタが有効ではありません"というエラーが返されます。回避策はありますか?私はそれがC#が "アクション"を生成する方法と関係があると思います。
//C++/CLI code
ref class Foo
{
public:
Foo(IEventAggregator^ aggregator)
{
void InitializeComponent();
this->_aggregator = aggregator;
if (this->_aggregator == nullptr)
throw gcnew Exception("null pointer");
//error in the following line on Hander, a pointer-to-member is not valid for a managed class
_subToken = _aggregator->GetEvent<fooEvent^>()->Subscribe(Handler, ThreadOption::UIThread, false);
private:
IEventAggregator^_aggregator;
SubscriptionToken^_addActorPipelineToken = nullptr;
void Handler(fooEventPayload^ args)
{
//this gets run on the event
}
}