How do I create a custom Find method for a Generic::List<T> in C++/CLI?

旧城冷巷雨未停 提交于 2019-12-08 11:22:59

问题


I wanted to post an answer to this question because the MSDN Network Example only lists C# and VB and the answer is a bit different in C++/CLI.

This answer is derived from this post: Using "->Find" on a "List" in Visual C++


回答1:


Following the guidance of the post link above...

First I created a class to use as my Predicate delegate:

public value class FindComponentView
{
  String^ Value;

public:

  FindComponentView(String^ value)
  {
    Value = value;
  }
  bool IsMatch(ComponentDrawingData^ compDD)
  {
    return compDD->Identifier->Value == Value;
  }
};

I was then able to implement the Find() method like this:

// Note: ComponentDrawingDataList^ derives from System::Collections::Generic::List<T>^

ComponentDrawingDataList^ ddList = GetComponentDrawingDatas(component);
ComponentDrawingData^ componentDrawingData = 
  ddList->Find(gcnew System::Predicate<ComponentDrawingData^>(gcnew FindComponentView("View_1"), &FindComponentView::IsMatch));


来源:https://stackoverflow.com/questions/37354500/how-do-i-create-a-custom-find-method-for-a-genericlistt-in-c-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!